feat: v0.2.0 — key-only frontmatter edits, link-complete move, --no-open/--print-path

- frontmatter --edit/--clear/--delete splice only the targeted keys; values written
  as Obsidian stores them (plain or double-quoted, no \xE9 escapes, no folding)
- move rewrites [[name|alias]], [[name#heading]], embeds, path and frontmatter links,
  escapes names, refuses to overwrite, leaves ambiguous bare links alone
- periodic commands: --no-open, --print-path
- stdout/stderr are UTF-8 with LF on every OS
This commit is contained in:
olivier committed 2026-10-19 11:42:25 -04:00
1 parent d77fac61c8
commit 543ce76207
3 files changed
+337 -149

No files matched your search

+92 -2
View File
@@ -186,8 +186,8 @@ Test content"""
self.cli.frontmatter_clear(test_note, ('status,title',))
content = (self.test_dir / test_note).read_text(encoding='utf-8-sig')
frontmatter = yaml.safe_load(content.split('---')[1])
self.assertEqual(frontmatter['status'], '')
self.assertEqual(frontmatter['title'], '')
self.assertIsNone(frontmatter['status'])
self.assertIsNone(frontmatter['title'])
# Test frontmatter --delete
self.cli.frontmatter_delete(test_note, ('tags',))
@@ -218,6 +218,96 @@ Test content"""
link_content = (self.test_dir / 'link.md').read_text(encoding='utf-8-sig')
self.assertIn('[[dest]]', link_content)
def test_frontmatter_edit_only_touches_target_keys(self):
"""Editing keys keeps order, quoting, accents and long lines of the rest"""
note = self.test_dir / 'meeting.md'
note.write_text(
'---\n'
'client: "[[Symbolitech]]"\n'
'participants:\n'
' - "[[Stéphane Charbonneau|Stéphane]]"\n'
'type: meeting\n'
'summary: "Une longue phrase de résumé qui dépasse largement quatre-vingts caractères sans être repliée."\n'
'date: 2026-10-19\n'
'---\n'
'# Réunion\n', encoding='utf-8')
self.cli.frontmatter_edit('meeting', ('type', 'status', 'parent', 'reviewed'),
('réunion', 'done', '[[Haro]]', '2026-10-20'))
self.cli.frontmatter_delete('meeting', ('client',))
self.assertEqual(note.read_text(encoding='utf-8'),
'---\n'
'participants:\n'
' - "[[Stéphane Charbonneau|Stéphane]]"\n'
'type: réunion\n'
'summary: "Une longue phrase de résumé qui dépasse largement quatre-vingts caractères sans être repliée."\n'
'date: 2026-10-19\n'
'status: done\n'
'parent: "[[Haro]]"\n'
'reviewed: 2026-10-20\n'
'---\n'
'# Réunion\n')
def test_frontmatter_edit_adds_frontmatter_to_plain_note(self):
note = self.test_dir / 'plain.md'
note.write_text('Corps\n---\nPas un frontmatter\n', encoding='utf-8')
self.cli.frontmatter_edit('plain', ('tags',), ('a, b',))
self.assertEqual(note.read_text(encoding='utf-8'),
'---\ntags:\n - a\n - b\n---\nCorps\n---\nPas un frontmatter\n')
def test_move_rewrites_every_link_form(self):
"""Aliases, headings, embeds, path links, frontmatter links, regex characters"""
(self.test_dir / 'films').mkdir()
(self.test_dir / 'films' / 'Dune (film).md').write_text('Self: [[Dune (film)#Notes]]\n', encoding='utf-8')
linker = self.test_dir / 'index.md'
linker.write_text(
'---\nrelated: "[[Dune (film)|Dune]]"\n---\n'
'[[Dune (film)]] [[dune (film)#Cast|vu]] ![[Dune (film)#^b1]] '
'[[films/Dune (film).md]] [[Dune]] [[Other (film)]]\n', encoding='utf-8')
with patch('click.echo') as echo:
self.cli.move_note('films/Dune (film)', 'archives/Dune 2021')
echo.assert_any_call('Moved films/Dune (film) to archives/Dune 2021 (6 link(s) updated in 2 note(s))')
self.assertEqual(linker.read_text(encoding='utf-8'),
'---\nrelated: "[[Dune 2021|Dune]]"\n---\n'
'[[Dune 2021]] [[Dune 2021#Cast|vu]] ![[Dune 2021#^b1]] '
'[[archives/Dune 2021.md]] [[Dune]] [[Other (film)]]\n')
self.assertEqual((self.test_dir / 'archives' / 'Dune 2021.md').read_text(encoding='utf-8'),
'Self: [[Dune 2021#Notes]]\n')
def test_move_ambiguous_names(self):
"""Bare links to a non-unique old name stay; a non-unique new name gets a path link"""
for rel in ('a/Note.md', 'b/Note.md', 'c/Target.md', 'd/Old.md'):
(self.test_dir / rel).parent.mkdir(exist_ok=True)
(self.test_dir / rel).write_text('', encoding='utf-8')
linker = self.test_dir / 'links.md'
linker.write_text('[[Note]] [[a/Note]] [[Old]]\n', encoding='utf-8')
self.cli.move_note('a/Note', 'e/Renamed')
self.cli.move_note('d/Old', 'f/Target')
self.assertEqual(linker.read_text(encoding='utf-8'), '[[Note]] [[e/Renamed]] [[f/Target]]\n')
def test_move_refuses_to_overwrite(self):
self.cli.create_note('one.md', '1')
self.cli.create_note('two.md', '2')
with self.assertRaises(click.UsageError):
self.cli.move_note('one', 'two')
self.assertEqual((self.test_dir / 'two.md').read_text(encoding='utf-8'), '2')
self.assertTrue((self.test_dir / 'one.md').exists())
def test_periodic_no_open_print_path(self):
"""--no-open creates without opening Obsidian; --print-path prints only the path"""
expected = self.test_dir.resolve() / '2025-10-24.md'
with patch.object(OnyxCLI, 'open_note') as open_note, patch('click.echo') as echo:
self.cli.daily_note(date='2025-10-24', open_after=False, print_path=True)
self.cli.daily_note(date='2025-10-24', open_after=False, print_path=True)
open_note.assert_not_called()
self.assertEqual([c.args for c in echo.call_args_list], [(str(expected),), (str(expected),)])
self.assertTrue(expected.exists())
def test_daily_note(self):
"""Test daily note creation"""
# Mock datetime.now() to return a specific date