1 Commits
Author SHA1 Message Date
olivier d063551a1e feat: v0.4.0 — section, resolve, list, tasks
- section: append to / replace one section, list-aware spacing, fences ignored
- resolve: filename or alias, case/accent-insensitive, --link wikilinks
- list: frontmatter filters (key=value, key!=value, key, !key), --json
- tasks: checkbox tasks by folder, date range, status, --ignore-from template, --json
- libyaml loader for whole-vault scans
2026-10-19 11:59:16 -04:00
3 changed files with 500 additions and 1 deletions

No files matched your search

+46
View File
@@ -256,6 +256,50 @@ splitting) and matched by wikilink target, so `[[Name|Alias]]` and `[[name]]` ar
`--add` skips duplicates, creates the list if the key is missing, and turns a text value into the `--add` skips duplicates, creates the list if the key is missing, and turns a text value into the
first item. A list holding unquoted `[[links]]` (which YAML reads as nested lists) is refused. first item. A list holding unquoted `[[links]]` (which YAML reads as nested lists) is refused.
### Editing One Section
```bash
# Append at the end of a section (before the next heading of the same or a higher level)
onyx section "periodic/daily/2026-10-19" --heading "## Journal" --content "### 10:00 - Titre\n- note"
onyx section "periodic/daily/2026-10-19" --heading "### Matin" --content "- [ ] Appeler Haro"
# Replace a section's body; --content - reads stdin; --create adds a missing section at the end
onyx section "periodic/weekly/2026-W43" --heading "## Weekly review" --replace --create --content - < review.md
```
`--heading "## Journal"` matches that level only; `--heading Journal` matches any level (case-insensitive).
Appended text gets a blank line before it, except between two list items, so a list stays one list.
Headings in the frontmatter or in code blocks are ignored, and everything outside the section is left
byte-for-byte. A missing heading is an error (listing the note's headings) unless `--create`.
### Finding Notes
```bash
# By filename or alias: exact, ignoring case and accents; exit code 1 when nothing matches
onyx resolve "Stéphane" --folder entities --link # [[Stéphane Charbonneau|Stéphane]], one line per match
onyx resolve "METC" # entities/businesses/Mousquetons et Cie
# By frontmatter (repeatable --where = AND): key=value, key!=value, key, !key
onyx list --folder projects --where type=project --where status=active
onyx list --where client=Symbolitech --where "status!=done" --json
```
`--where` values compare without case or accents, a `[[link]]` compares by its target, and a list matches
when any item does. `resolve --link` uses a path link when the filename is shared by several notes.
### Tasks
```bash
# Open and in-progress tasks of a week's daily notes, minus the template's recurring ones
onyx tasks --folder periodic/daily --from 2026-10-12 --to 2026-10-18 --status open,doing \
--ignore-from resources/template/daily-note
onyx tasks --folder projects --status open --json # path, line, date, status, heading, text
```
Statuses: `- [ ]` open, `- [/]` doing, `- [x]` done, `- [-]` cancelled. With `--from`/`--to`, a note's
date is the `YYYY-MM-DD` at the start of its filename, else its `date` property; undated notes are
skipped. Output is `path:line: - [ ] text`, like grep.
### Version ### Version
```bash ```bash
@@ -272,6 +316,8 @@ onyx --version
- **Periodic Notes**: Support for daily, weekly, monthly, quarterly, and yearly notes - **Periodic Notes**: Support for daily, weekly, monthly, quarterly, and yearly notes
- **Frontmatter Management**: Edit, view, clear, and delete YAML frontmatter - **Frontmatter Management**: Edit, view, clear, and delete YAML frontmatter
- **Link Updates**: Automatically update internal links when moving notes - **Link Updates**: Automatically update internal links when moving notes
- **Sections**: Append to or replace one section of a note
- **Queries**: Resolve notes by name/alias, list notes by frontmatter, list tasks by date and status
- **Cross-Platform**: Works on macOS, Windows, and Linux - **Cross-Platform**: Works on macOS, Windows, and Linux
## Requirements ## Requirements
+330 -1
View File
@@ -9,6 +9,7 @@ import datetime
import builtins import builtins
from pathlib import Path from pathlib import Path
import re import re
import unicodedata
from collections import Counter from collections import Counter
from typing import List, Union, Optional, Dict, Any from typing import List, Union, Optional, Dict, Any
from urllib.parse import quote from urllib.parse import quote
@@ -90,6 +91,144 @@ def _iter_notes(vault_path: Path):
yield path yield path
_HEADING = re.compile(r'^(#{1,6})[ \t]+(.*?)[ \t]*$')
_FENCE = re.compile(r'^[ \t]*(`{3,}|~{3,})')
_LIST_ITEM = re.compile(r'^[ \t]*([-*+]|\d+[.)])[ \t]')
def _section_bounds(lines: List[str], first: int, heading: str) -> Optional[tuple]:
"""(heading line, end line) of the first section titled `heading`, skipping fenced code.
`heading` is "## Title" (that level only) or "Title" (any level); case-insensitive.
The section ends at the next heading of the same or a higher level, or at EOF."""
wanted = _HEADING.match(heading.strip())
level_wanted, title_wanted = (len(wanted.group(1)), wanted.group(2)) if wanted else (None, heading.strip())
fence, start, level = None, None, None
for i in range(first, len(lines)):
line = lines[i].rstrip('\n')
fence_match = _FENCE.match(line)
if fence_match:
marker = fence_match.group(1)[0]
fence = None if fence == marker else (fence or marker)
continue
match = None if fence else _HEADING.match(line)
if not match:
continue
if start is None:
if (match.group(2).casefold() == title_wanted.casefold()
and level_wanted in (None, len(match.group(1)))):
start, level = i, len(match.group(1))
elif len(match.group(1)) <= level:
return start, i
return (start, len(lines)) if start is not None else None
def _write_section(text: str, heading: str, content: str, replace: bool = False, create: bool = False) -> str:
"""Append `content` at the end of a section (or replace the section's body).
Appending adds a blank line before the new content, except between two list items so
a list stays one list. Blank lines before the next heading are preserved. A missing
section raises KeyError unless `create`, which adds it at the end of the note."""
match = _FRONTMATTER.match(text)
lines = text.splitlines(keepends=True)
if lines and not lines[-1].endswith('\n'):
lines[-1] += '\n'
new = [line + '\n' for line in content.strip('\n').split('\n')] if content.strip() else []
bounds = _section_bounds(lines, text[:match.end()].count('\n') if match else 0, heading)
if bounds is None:
if not create:
raise KeyError(heading)
title = heading.strip() if heading.strip().startswith('#') else f"## {heading.strip()}"
while lines and not lines[-1].strip():
lines.pop()
return ''.join(lines + (['\n'] if lines else []) + [title + '\n'] + new)
start, end = bounds
body = lines[start + 1:end]
keep = len(body)
while keep and not body[keep - 1].strip():
keep -= 1
kept, trailing = body[:keep], body[keep:]
if replace:
kept = new
elif new:
lists_touch = kept and _LIST_ITEM.match(kept[-1]) and _LIST_ITEM.match(new[0])
kept = kept + ([] if not kept or lists_touch else ['\n']) + new
return ''.join(lines[:start + 1] + kept + trailing + lines[end:])
_TASK = re.compile(r'^[ \t]*[-*+][ \t]+\[(.)\][ \t]+(.*?)[ \t]*$')
_TASK_STATUS = {' ': 'open', 'x': 'done', 'X': 'done', '/': 'doing', '-': 'cancelled'}
_DATE_PREFIX = re.compile(r'^(\d{4}-\d{2}-\d{2})')
_YAML_LOADER = getattr(yaml, 'CSafeLoader', yaml.SafeLoader) # libyaml: ~7x faster on whole-vault scans
def _read_frontmatter(text: str, needed: Optional[str] = None) -> dict:
"""Frontmatter as a dict; {} when missing or invalid YAML. With `needed`, skip the
YAML parse when that key name doesn't even appear in the frontmatter."""
match = _FRONTMATTER.match(text)
if not match or (needed and needed not in match.group(1)):
return {}
try:
data = yaml.load(match.group(1), Loader=_YAML_LOADER)
except yaml.YAMLError:
return {}
return data if isinstance(data, dict) else {}
def _fold(value: Any) -> str:
"""Comparison form: wikilink target if the value is one link, accents and case removed."""
text = str(value).strip()
link = _WIKILINK.fullmatch(text)
if link:
text = link.group(1).strip()
decomposed = unicodedata.normalize('NFKD', text)
return ''.join(c for c in decomposed if not unicodedata.combining(c)).casefold()
def _where_matches(frontmatter: dict, expression: str) -> bool:
"""key=value, key!=value, key (present and non-empty), !key (missing or empty).
A list matches `=` when any item matches."""
match = re.fullmatch(r'\s*(!?)([^=!]+?)\s*(?:(!?=)\s*(.*?))?\s*', expression)
if not match:
raise click.UsageError(f"Invalid --where '{expression}': use key=value, key!=value, key or !key")
negate_key, key, operator, wanted = match.groups()
value = frontmatter.get(key)
items = value if isinstance(value, list) else ([] if value in (None, '') else [value])
if operator is None:
return not items if negate_key else bool(items)
found = any(_fold(item) == _fold(wanted) for item in items)
return found if operator == '=' else not found
def _iter_tasks(text: str):
"""(line number, status char, text, nearest heading) for each checkbox outside
frontmatter and fenced code."""
match = _FRONTMATTER.match(text)
lines = text.splitlines()
fence, heading = None, ''
for number in range(text[:match.end()].count('\n') if match else 0, len(lines)):
line = lines[number]
fence_match = _FENCE.match(line)
if fence_match:
marker = fence_match.group(1)[0]
fence = None if fence == marker else (fence or marker)
continue
if fence:
continue
heading_match = _HEADING.match(line)
if heading_match:
heading = heading_match.group(2)
continue
task = _TASK.match(line)
if task:
yield number + 1, task.group(1), task.group(2), heading
class OnyxCLI: class OnyxCLI:
_PERIODIC_DEFAULTS: Dict[str, Dict[str, str]] = { _PERIODIC_DEFAULTS: Dict[str, Dict[str, str]] = {
'daily': {'format': 'YYYY-MM-DD', 'folder': '', 'template': ''}, 'daily': {'format': 'YYYY-MM-DD', 'folder': '', 'template': ''},
@@ -540,6 +679,107 @@ class OnyxCLI:
"""Create or open a yearly note for a specific date, next, or previous year.""" """Create or open a yearly note for a specific date, next, or previous year."""
self._create_or_open_periodic_note('yearly', vault, date, next_, previous, open_after, print_path) self._create_or_open_periodic_note('yearly', vault, date, next_, previous, open_after, print_path)
def write_section(self, note_name: str, heading: str, content: str, replace: bool = False,
create: bool = False, vault: str = None):
"""Append to (or replace) one section of a note; the rest of the note is untouched."""
vault_name, vault_path = self._get_vault_and_path(vault)
note_path = self._find_note(vault_path, note_name)
text = note_path.read_text(encoding='utf-8-sig')
try:
new_text = _write_section(text, heading, content, replace, create)
except KeyError:
lines = text.splitlines()
headings = [line for line in lines if _HEADING.match(line)]
raise click.UsageError(f"Heading '{heading}' not found in {note_name} (use --create to add it). "
f"Headings: {', '.join(headings) or 'none'}")
if new_text != text:
_write_text(note_path, new_text)
click.echo(f"{'Replaced' if replace else 'Updated'} section '{heading}' in {note_name}")
def resolve_note(self, name: str, folder: str = None, link: bool = False, vault: str = None) -> int:
"""Print notes whose filename or one of whose aliases equals `name` (case and accents
ignored, no fuzzy matching). Returns the number of matches."""
vault_name, vault_path = self._get_vault_and_path(vault)
notes = list(_iter_notes(vault_path))
stems = Counter(p.stem.casefold() for p in notes)
wanted = _fold(name)
matches = 0
for note in sorted(notes):
if folder and not note.relative_to(vault_path).as_posix().startswith(folder.strip('/') + '/'):
continue
if _fold(note.stem) == wanted:
display = None
else:
text = note.read_text(encoding='utf-8-sig')
aliases = _read_frontmatter(text, needed='aliases').get('aliases') or []
aliases = aliases if isinstance(aliases, list) else [aliases]
display = next((str(a) for a in aliases if a is not None and _fold(a) == wanted), None)
if display is None:
continue
matches += 1
rel = note.relative_to(vault_path).with_suffix('').as_posix()
if link:
target = note.stem if stems[note.stem.casefold()] == 1 else rel
click.echo(f"[[{target}|{display}]]" if display else f"[[{target}]]")
else:
click.echo(rel)
return matches
def _notes_in(self, vault_path: Path, folder: Optional[str]) -> List[Path]:
base = vault_path / folder if folder else vault_path
if not base.is_dir():
raise click.UsageError(f"Folder {folder} does not exist")
return sorted(p for p in _iter_notes(vault_path) if base in p.parents)
def list_notes(self, folder: str = None, where: tuple = (), as_json: bool = False, vault: str = None):
"""Notes whose frontmatter matches every --where expression."""
vault_name, vault_path = self._get_vault_and_path(vault)
results = []
for note in self._notes_in(vault_path, folder):
frontmatter = _read_frontmatter(note.read_text(encoding='utf-8-sig'))
if all(_where_matches(frontmatter, expression) for expression in where):
results.append((note.relative_to(vault_path).with_suffix('').as_posix(), frontmatter))
if as_json:
click.echo(json.dumps([{'path': rel, 'frontmatter': fm} for rel, fm in results],
ensure_ascii=False, indent=2, default=str))
else:
for rel, _ in results:
click.echo(rel)
def list_tasks(self, folder: str = None, date_from: str = None, date_to: str = None,
statuses: Optional[set] = None, ignore_from: str = None, as_json: bool = False,
vault: str = None):
"""Checkbox tasks across notes. With --from/--to, a note's date is its filename's
YYYY-MM-DD prefix, else its `date` property; undated notes are skipped."""
vault_name, vault_path = self._get_vault_and_path(vault)
ignored = set()
if ignore_from:
text = self._find_note(vault_path, ignore_from).read_text(encoding='utf-8-sig')
ignored = {_fold(task_text) for _, _, task_text, _ in _iter_tasks(text)}
results = []
for note in self._notes_in(vault_path, folder):
text = note.read_text(encoding='utf-8-sig')
prefix = _DATE_PREFIX.match(note.stem)
note_date = prefix.group(1) if prefix else str(_read_frontmatter(text).get('date') or '')[:10]
if (date_from or date_to) and not _DATE_PREFIX.match(note_date):
continue
if (date_from and note_date < date_from) or (date_to and note_date > date_to):
continue
rel = note.relative_to(vault_path).as_posix()
for line, char, task_text, heading in _iter_tasks(text):
status = _TASK_STATUS.get(char, char)
if (statuses and status not in statuses) or _fold(task_text) in ignored:
continue
results.append({'path': rel, 'line': line, 'date': note_date or None, 'status': status,
'heading': heading, 'text': task_text, 'char': char})
if as_json:
click.echo(json.dumps([{k: v for k, v in r.items() if k != 'char'} for r in results],
ensure_ascii=False, indent=2))
else:
for r in results:
click.echo(f"{r['path']}:{r['line']}: - [{r['char']}] {r['text']}")
def print_note(self, note_name: str, vault: str = None): def print_note(self, note_name: str, vault: str = None):
vault_name, vault_path = self._get_vault_and_path(vault) vault_name, vault_path = self._get_vault_and_path(vault)
note_path = vault_path / note_name note_path = vault_path / note_name
@@ -974,7 +1214,7 @@ def _periodic_output_options(command):
help="Don't open Obsidian; a newly created note keeps raw Templater syntax " help="Don't open Obsidian; a newly created note keeps raw Templater syntax "
"until Obsidian processes it")(command) "until Obsidian processes it")(command)
@click.version_option(version='0.3.0', prog_name='onyx') @click.version_option(version='0.4.0', prog_name='onyx')
@click.group(name='onyx') @click.group(name='onyx')
def cli(): def cli():
"""Onyx - Interact with Obsidian vaults from the command line """Onyx - Interact with Obsidian vaults from the command line
@@ -1142,6 +1382,95 @@ def create(note_name, content, vault, overwrite, append, open_after, template):
content = content.replace('\\n', '\n') content = content.replace('\\n', '\n')
OnyxCLI().create_note(note_name, content, vault, overwrite, append, open_after, template) OnyxCLI().create_note(note_name, content, vault, overwrite, append, open_after, template)
@cli.command()
@click.argument('note_name')
@click.option('--heading', required=True,
help="Section title: '## Journal' (that level) or 'Journal' (any level); case-insensitive")
@click.option('--content', required=True, help="Text to insert; '-' reads stdin; literal \\n becomes a newline")
@click.option('--replace', is_flag=True, help="Replace the section's body instead of appending to it")
@click.option('--create', is_flag=True, help="Add the section at the end of the note if it is missing")
@click.option('--vault', help="Vault name (if not using default)")
def section(note_name, heading, content, replace, create, vault):
"""Append to, or replace, one section of a note
Appends at the end of the section (before the next heading of the same or a
higher level), after a blank line, except between two list items. Headings in
code blocks are ignored. Everything outside the section stays byte-for-byte.
USAGE:
onyx section "periodic/daily/2026-10-19" --heading "## Journal" --content "### 10:00 - Titre\\n- note"
onyx section "periodic/daily/2026-10-19" --heading "### Matin" --content "- [ ] Appeler Haro"
onyx section "periodic/weekly/2026-W43" --heading "## Weekly review" --replace --content - < review.md
"""
content = sys.stdin.read() if content == '-' else content.replace('\\n', '\n')
OnyxCLI().write_section(note_name, heading, content, replace, create, vault)
@cli.command()
@click.argument('name')
@click.option('--folder', help="Only notes under this vault-relative folder (e.g. entities)")
@click.option('--link', is_flag=True, help="Print a ready-to-paste wikilink instead of the path")
@click.option('--vault', help="Vault name (if not using default)")
def resolve(name, folder, link, vault):
"""Find notes by filename or alias
Exact match on the filename or any `aliases` entry, ignoring case and accents
(no fuzzy matching). Prints one vault-relative path per match; exits 1 when
nothing matches. --link prints [[Note]] or [[Note|Alias]] (a path link when the
filename is shared by several notes).
USAGE:
onyx resolve "Stéphane" --folder entities --link
onyx resolve "METC"
"""
if not OnyxCLI().resolve_note(name, folder, link, vault):
click.echo(f"No note named or aliased '{name}'", err=True)
sys.exit(1)
@cli.command(name='list')
@click.option('--folder', help="Only notes under this vault-relative folder")
@click.option('--where', multiple=True,
help="Frontmatter filter, repeatable (AND): key=value, key!=value, key, !key")
@click.option('--json', 'as_json', is_flag=True, help="Print paths and frontmatter as JSON")
@click.option('--vault', help="Vault name (if not using default)")
def list_command(folder, where, as_json, vault):
"""List notes, filtered by frontmatter
Values compare without case or accents; a [[link]] compares by its target, and a
list matches when any item does. Prints vault-relative paths, or JSON with --json.
USAGE:
onyx list --folder projects --where type=project --where status=active
onyx list --where client=Symbolitech --where "status!=done" --json
"""
OnyxCLI().list_notes(folder, where, as_json, vault)
@cli.command()
@click.option('--folder', help="Only notes under this vault-relative folder (e.g. periodic/daily)")
@click.option('--from', 'date_from', help="First note date (YYYY-MM-DD), inclusive")
@click.option('--to', 'date_to', help="Last note date (YYYY-MM-DD), inclusive")
@click.option('--status', help="Comma-separated: open, doing, done, cancelled (default: all)")
@click.option('--ignore-from', help="Skip tasks whose text also appears in this note (e.g. the daily template)")
@click.option('--json', 'as_json', is_flag=True, help="JSON with path, line, date, status, heading, text")
@click.option('--vault', help="Vault name (if not using default)")
def tasks(folder, date_from, date_to, status, ignore_from, as_json, vault):
"""List checkbox tasks: - [ ] open, - [/] doing, - [x] done, - [-] cancelled
With --from/--to, a note's date is the YYYY-MM-DD at the start of its filename,
else its `date` property; undated notes are skipped. Tasks in code blocks are ignored.
USAGE:
onyx tasks --folder periodic/daily --from 2026-10-12 --to 2026-10-18 --status open \\
--ignore-from resources/template/daily-note
"""
for value in (date_from, date_to):
if value and not re.fullmatch(r'\d{4}-\d{2}-\d{2}', value):
raise click.UsageError(f"Invalid date '{value}': use YYYY-MM-DD")
statuses = {s.strip() for s in status.split(',')} if status else None
unknown = (statuses or set()) - set(_TASK_STATUS.values())
if unknown:
raise click.UsageError(f"Unknown status {', '.join(sorted(unknown))}: use open, doing, done, cancelled")
OnyxCLI().list_tasks(folder, date_from, date_to, statuses, ignore_from, as_json, vault)
@cli.command() @cli.command()
@click.argument('note_name') @click.argument('note_name')
@click.option('--vault', help="Vault name (if not using default)") @click.option('--vault', help="Vault name (if not using default)")
+124
View File
@@ -1,3 +1,4 @@
import json
import os import os
import unittest import unittest
import yaml import yaml
@@ -252,6 +253,129 @@ Test content"""
self.cli.frontmatter_list_items('bad', 'related', ('[[Plane]]',)) self.cli.frontmatter_list_items('bad', 'related', ('[[Plane]]',))
self.assertEqual(note.read_text(encoding='utf-8'), content) self.assertEqual(note.read_text(encoding='utf-8'), content)
DAILY = (
'---\n'
'type: daily-note\n'
'# Journal: not a heading inside frontmatter\n'
'---\n'
'\n'
'# 2026-10-29\n'
'\n'
'## To do\n'
'### Matin\n'
'- [ ] Regarder ma Weekly note\n'
'\n'
'### Après-midi\n'
'\n'
'### Soir\n'
'- [ ] Prendre calcium\n'
'\n'
'```markdown\n'
'## Journal\n'
'```\n'
'\n'
'## Journal\n'
'Aujourd’hui, Mark présente Align.')
def _daily(self):
note = self.test_dir / 'd.md'
note.write_text(self.DAILY, encoding='utf-8')
return note
def test_section_append(self):
"""Blank line before new blocks, none between list items or after an empty heading;
headings in frontmatter or code fences are ignored; nothing else moves"""
note = self._daily()
self.cli.write_section('d', '## Journal', '### 10:00 - Ménage\n- fait')
self.cli.write_section('d', 'matin', '- [ ] Appeler Haro')
self.cli.write_section('d', '### Après-midi', '- [ ] Courses\n')
self.cli.write_section('d', '## Journal', '### 11:00')
self.assertEqual(note.read_text(encoding='utf-8'), self.DAILY
.replace('- [ ] Regarder ma Weekly note\n', '- [ ] Regarder ma Weekly note\n- [ ] Appeler Haro\n')
.replace('### Après-midi\n', '### Après-midi\n- [ ] Courses\n')
.replace('Align.', 'Align.\n\n### 10:00 - Ménage\n- fait\n\n### 11:00\n'))
def test_section_replace_keeps_neighbours(self):
"""Replacing '## To do' drops its subsections and the code block inside it, but stops
at '## Journal' (the fake one in the fence doesn't end the section)"""
note = self._daily()
self.cli.write_section('d', '## To do', '- [ ] Une seule tâche', replace=True)
self.cli.write_section('d', '## Journal', '', replace=True)
self.assertEqual(note.read_text(encoding='utf-8'),
'---\ntype: daily-note\n# Journal: not a heading inside frontmatter\n---\n\n# 2026-10-29\n\n'
'## To do\n- [ ] Une seule tâche\n\n## Journal\n')
def test_section_missing_heading(self):
note = self._daily()
with self.assertRaises(click.UsageError):
self.cli.write_section('d', '## Review', 'x')
self.assertEqual(note.read_text(encoding='utf-8'), self.DAILY)
self.cli.write_section('d', 'Review', 'Bilan', create=True)
self.assertEqual(note.read_text(encoding='utf-8'), self.DAILY + '\n\n## Review\nBilan\n')
def _write_notes(self, notes: dict):
for rel, text in notes.items():
path = self.test_dir / rel
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(text, encoding='utf-8')
def _echoed(self, call, *args, **kwargs):
with patch('click.echo') as echo:
result = call(*args, **kwargs)
return [c.args[0] for c in echo.call_args_list], result
def test_resolve_by_name_or_alias(self):
"""Case/accent-insensitive exact match; alias gives [[Note|Alias]]; shared filename
gives a path link; no fuzzy match"""
self._write_notes({
'entities/people/Stéphane Charbonneau.md': '---\naliases:\n - Stéphane\n---\n',
'entities/people/Stéphane Bigham.md': '---\naliases: [stephane]\n---\n',
'entities/businesses/Securitech.md': '---\naliases:\n - Sécuritech\n---\n',
'entities/businesses/Haro.md': '',
'archives/Haro.md': '',
'.trash/Securitech.md': '',
})
self.assertEqual(self._echoed(self.cli.resolve_note, 'STEPHANE', link=True),
(['[[Stéphane Bigham|stephane]]', '[[Stéphane Charbonneau|Stéphane]]'], 2))
self.assertEqual(self._echoed(self.cli.resolve_note, 'sécuritech'),
(['entities/businesses/Securitech'], 1))
self.assertEqual(self._echoed(self.cli.resolve_note, 'haro', folder='entities', link=True),
(['[[entities/businesses/Haro]]'], 1))
self.assertEqual(self._echoed(self.cli.resolve_note, 'Charbonneau'), ([], 0))
def test_list_where(self):
self._write_notes({
'projects/A.md': '---\ntype: project\nstatus: active\nclient: "[[Symbolitech]]"\n---\n',
'projects/B.md': '---\ntype: project\nstatus: done\nclient: "[[Diakonos]]"\n---\n',
'projects/C.md': '---\ntype: project\ntags:\n - Écriture\n---\n',
'notes/D.md': '---\ntype: project\nstatus: active\n---\n',
})
list_notes = self.cli.list_notes
self.assertEqual(self._echoed(list_notes, 'projects', ('status=ACTIVE', 'client=symbolitech'))[0],
['projects/A'])
self.assertEqual(self._echoed(list_notes, 'projects', ('status!=done', 'type'))[0],
['projects/A', 'projects/C'])
self.assertEqual(self._echoed(list_notes, None, ('!status',))[0], ['projects/C'])
self.assertEqual(self._echoed(list_notes, 'projects', ('tags=ecriture',))[0], ['projects/C'])
def test_tasks_dates_statuses_and_template(self):
self._write_notes({
'template.md': '- [ ] Prendre calcium\n',
'daily/2026-10-12.md': '## To do\n### Matin\n- [ ] Appeler Haro\n- [x] Fait\n- [/] En cours\n'
'```\n- [ ] dans du code\n```\n## Soir\n - [ ] prendre CALCIUM\n- [-] Annulé\n',
'daily/2026-10-20.md': '- [ ] Trop tard\n',
'daily/Sans date.md': '---\ndate: 2026-10-13\n---\n- [ ] Daté par la propriété\n',
})
lines, _ = self._echoed(self.cli.list_tasks, 'daily', '2026-10-12', '2026-10-18',
{'open', 'doing'}, 'template')
self.assertEqual(lines, ['daily/2026-10-12.md:3: - [ ] Appeler Haro',
'daily/2026-10-12.md:5: - [/] En cours',
'daily/Sans date.md:4: - [ ] Daté par la propriété'])
output, _ = self._echoed(self.cli.list_tasks, 'daily', statuses={'cancelled'}, as_json=True)
self.assertEqual(json.loads(output[0]), [{'path': 'daily/2026-10-12.md', 'line': 11, 'date': '2026-10-12',
'status': 'cancelled', 'heading': 'Soir', 'text': 'Annulé'}])
def test_move_rewrites_every_link_form(self): def test_move_rewrites_every_link_form(self):
"""Aliases, headings, embeds, path links, frontmatter links, regex characters""" """Aliases, headings, embeds, path links, frontmatter links, regex characters"""
(self.test_dir / 'films').mkdir() (self.test_dir / 'films').mkdir()