Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
812d8d7ea5 | ||
|
|
7f6b598c4a | ||
|
|
b2f609ec4a | ||
|
|
33544edf07 | ||
|
|
34d28c03fa | ||
|
|
d063551a1e | ||
|
|
3d3873b699 | ||
|
|
0f763f98ed | ||
|
|
543ce76207 |
No files matched your search
@@ -71,6 +71,13 @@ onyx open "note-name"
|
|||||||
onyx open "note-name" --vault "vault-name"
|
onyx open "note-name" --vault "vault-name"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`open`, `print-note`, `section` and `frontmatter` find a note by its exact
|
||||||
|
vault-relative path, otherwise by filename or `aliases` entry (case and accents
|
||||||
|
ignored; a filename beats an alias) or by a partial path such as
|
||||||
|
`people/Haro`. When several notes match, nothing is opened and the candidate
|
||||||
|
paths are listed; when none match, close filenames are suggested. There is no
|
||||||
|
fuzzy opening. `move` and `delete` still require the exact path.
|
||||||
|
|
||||||
### Periodic Notes
|
### Periodic Notes
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -108,8 +115,16 @@ onyx weekly --previous # opens last week's note
|
|||||||
onyx monthly --next # opens next month's note
|
onyx monthly --next # opens next month's note
|
||||||
onyx quarterly --next # opens next quarter's note
|
onyx quarterly --next # opens next quarter's note
|
||||||
onyx yearly --previous # opens last year's note
|
onyx yearly --previous # opens last year's note
|
||||||
|
|
||||||
|
# Scripts and agents: create if missing without opening Obsidian, print only the path
|
||||||
|
onyx daily --date "2025-11-27" --no-open --print-path
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Output is UTF-8 with LF line endings on every OS, so `p=$(onyx daily --print-path)` works in
|
||||||
|
bash on Windows too. With `--no-open`, a newly created note keeps the template's raw Templater
|
||||||
|
syntax (`<% … %>`) until Obsidian processes it; when Obsidian is running, Templater's "trigger on
|
||||||
|
new file creation" renders it within seconds.
|
||||||
|
|
||||||
**Default filename formats** (used when nothing else is configured):
|
**Default filename formats** (used when nothing else is configured):
|
||||||
- Daily: `YYYY-MM-DD.md`
|
- Daily: `YYYY-MM-DD.md`
|
||||||
- Weekly: `YYYY-WWW.md` (ISO week, e.g. `2025-W48.md`)
|
- Weekly: `YYYY-WWW.md` (ISO week, e.g. `2025-W48.md`)
|
||||||
@@ -183,7 +198,8 @@ onyx print-note "note-name" --vault "vault-name"
|
|||||||
### Moving & Deleting Notes
|
### Moving & Deleting Notes
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Move or rename a note (auto-updates internal links)
|
# Move or rename a note; rewrites every wikilink that resolves to it:
|
||||||
|
# [[name]], [[name|alias]], [[name#heading]], ![[embeds]], [[folder/name]], frontmatter links
|
||||||
onyx move "old-path" "new-path"
|
onyx move "old-path" "new-path"
|
||||||
|
|
||||||
# Move in specific vault
|
# Move in specific vault
|
||||||
@@ -194,7 +210,14 @@ onyx move "old-path" "new-path" --open
|
|||||||
|
|
||||||
# Delete a note
|
# Delete a note
|
||||||
onyx delete "note-path"
|
onyx delete "note-path"
|
||||||
|
```
|
||||||
|
|
||||||
|
`move` refuses to overwrite an existing note. A bare `[[name]]` link is only rewritten when that
|
||||||
|
name was unique in the vault (otherwise it is reported and left alone); the new link stays bare
|
||||||
|
unless the new name is shared by another note, in which case it becomes a path link. Markdown
|
||||||
|
`[text](path.md)` links are not rewritten.
|
||||||
|
|
||||||
|
```bash
|
||||||
# Delete from specific vault
|
# Delete from specific vault
|
||||||
onyx delete "note-path" --vault "vault-name"
|
onyx delete "note-path" --vault "vault-name"
|
||||||
```
|
```
|
||||||
@@ -215,6 +238,10 @@ onyx frontmatter "note-name" --edit --key "tags" --value "project"
|
|||||||
onyx frontmatter "note-name" --edit --key "tags" --value "project,urgent"
|
onyx frontmatter "note-name" --edit --key "tags" --value "project,urgent"
|
||||||
onyx frontmatter "note-name" --edit --key "status" --value "in-progress"
|
onyx frontmatter "note-name" --edit --key "status" --value "in-progress"
|
||||||
|
|
||||||
|
# Add / remove single items of a list property (repeat --value for several items)
|
||||||
|
onyx frontmatter "note-name" --add --key "participants" --value "[[Haro]]" --value "[[Jeffrey]]"
|
||||||
|
onyx frontmatter "note-name" --remove --key "participants" --value "[[Haro]]"
|
||||||
|
|
||||||
# Clear frontmatter values
|
# Clear frontmatter values
|
||||||
onyx frontmatter "note-name" --clear --key "tags"
|
onyx frontmatter "note-name" --clear --key "tags"
|
||||||
onyx frontmatter "note-name" --clear --key "date,status,tags"
|
onyx frontmatter "note-name" --clear --key "date,status,tags"
|
||||||
@@ -224,6 +251,62 @@ onyx frontmatter "note-name" --delete --key "tags"
|
|||||||
onyx frontmatter "note-name" --delete --key "date,status,tags"
|
onyx frontmatter "note-name" --delete --key "date,status,tags"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Edits only touch the targeted keys: key order, quoting, accents and long values elsewhere in the
|
||||||
|
frontmatter stay byte-for-byte identical. Values are written the way Obsidian stores them: plain
|
||||||
|
when YAML reads them back unchanged (`done`, `2026-10-19`, `3`), double-quoted otherwise
|
||||||
|
(`"[[Haro]]"`). `tags`, and any key that is already a list in the note, take a comma-separated
|
||||||
|
list with `--edit`, written as a block list. Cleared keys become empty (`status:`), cleared tags
|
||||||
|
`tags: []`.
|
||||||
|
|
||||||
|
`--add` and `--remove` change one list without rewriting it: items are taken whole (no comma
|
||||||
|
splitting) and matched by wikilink target, so `[[Name|Alias]]` and `[[name]]` are the same item.
|
||||||
|
`--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.
|
||||||
|
|
||||||
|
### 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
|
||||||
@@ -240,11 +323,13 @@ 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
|
||||||
|
|
||||||
- Python 3.7+
|
- Python 3.9+ (only to run from source; the release binaries bundle Python)
|
||||||
- click
|
- click
|
||||||
- pyyaml
|
- pyyaml
|
||||||
|
|
||||||
|
|||||||
+13
-12
@@ -86,6 +86,11 @@ scratch vault/config — never against the real `~/.onyx-cli/config.yaml`.
|
|||||||
> **Windows gotcha**: the plain bash tool can't execute a freshly built
|
> **Windows gotcha**: the plain bash tool can't execute a freshly built
|
||||||
> `.exe` directly (`command not found`) — always invoke it through
|
> `.exe` directly (`command not found`) — always invoke it through
|
||||||
> `cmd.exe /c "onyx.exe ..."`.
|
> `cmd.exe /c "onyx.exe ..."`.
|
||||||
|
>
|
||||||
|
> **Linux scratch config**: run the smoke as a script file
|
||||||
|
> (`wsl -d Ubuntu-24.04 -- bash smoke.sh`), and save the binary path
|
||||||
|
> (`B=$HOME/onyx-build/dist/onyx`) before pointing `HOME` at a scratch
|
||||||
|
> directory, so the real config stays untouched.
|
||||||
|
|
||||||
## 5. Deploy locally (optional)
|
## 5. Deploy locally (optional)
|
||||||
|
|
||||||
@@ -129,33 +134,29 @@ git push origin vX.Y.Z
|
|||||||
|
|
||||||
## 7. Create the Gitea release
|
## 7. Create the Gitea release
|
||||||
|
|
||||||
`tea` hangs indefinitely under a plain non-interactive shell call, for
|
Use `gt` (gitea-cli 1.0+; `tea` is archived). `gt` never pushes, so step 6
|
||||||
*any* subcommand, including fully local ones. Always launch it as a
|
must be done first; `--verify-tag` refuses a tag the server doesn't have.
|
||||||
supervised process (hub `start`/`wait`/`logs`), never via the bash tool
|
From the bash tool, invoke it through `cmd.exe /c` like the exe above.
|
||||||
directly.
|
|
||||||
|
|
||||||
Write release notes to a scratch file, then create the release with both
|
Write release notes to a scratch file, then create the release with both
|
||||||
assets in one call:
|
assets in one call:
|
||||||
|
|
||||||
```
|
```
|
||||||
tea releases create --repo olivier/onyx-cli --tag vX.Y.Z --title vX.Y.Z \
|
gt release create vX.Y.Z dist/onyx.exe dist/onyx-linux --title vX.Y.Z \
|
||||||
--note-file release-notes-vX.Y.Z.md -a dist/onyx.exe -a dist/onyx-linux
|
--notes-file release-notes-vX.Y.Z.md --verify-tag --no-input
|
||||||
```
|
```
|
||||||
|
|
||||||
If the release already exists and you're adding a platform binary later
|
If the release already exists and you're adding a platform binary later
|
||||||
(e.g. the Linux build wasn't ready yet), attach it separately instead:
|
(e.g. the Linux build wasn't ready yet), attach it separately instead
|
||||||
|
(`--clobber` replaces an asset with the same name):
|
||||||
|
|
||||||
```
|
```
|
||||||
tea releases assets create --repo olivier/onyx-cli vX.Y.Z dist/<file>
|
gt release upload vX.Y.Z dist/<file>
|
||||||
```
|
```
|
||||||
|
|
||||||
Delete the scratch release-notes file afterward — it's not a repo
|
Delete the scratch release-notes file afterward — it's not a repo
|
||||||
convention file.
|
convention file.
|
||||||
|
|
||||||
> `tea repos create --owner olivier` fails with `GetOrgByName` — `--owner`
|
|
||||||
> targets an organization, not your personal account. Omit it entirely
|
|
||||||
> when creating a repo under your own user.
|
|
||||||
|
|
||||||
## 8. Verify the release
|
## 8. Verify the release
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
+661
-183
File diff suppressed because it is too large.
Load diff
+341
-79
@@ -1,4 +1,7 @@
|
|||||||
|
import json
|
||||||
import os
|
import os
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
import yaml
|
import yaml
|
||||||
import shutil
|
import shutil
|
||||||
@@ -9,6 +12,8 @@ import click
|
|||||||
from click.testing import CliRunner
|
from click.testing import CliRunner
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
SRC = Path(__file__).resolve().parent.parent / 'src' / 'onyx.py'
|
||||||
|
|
||||||
class TestOnyxCLI(unittest.TestCase):
|
class TestOnyxCLI(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
# Create temporary test directory and files
|
# Create temporary test directory and files
|
||||||
@@ -35,89 +40,12 @@ class TestOnyxCLI(unittest.TestCase):
|
|||||||
shutil.rmtree(self.test_dir, ignore_errors=True)
|
shutil.rmtree(self.test_dir, ignore_errors=True)
|
||||||
shutil.rmtree(self.temp_config_dir, ignore_errors=True)
|
shutil.rmtree(self.temp_config_dir, ignore_errors=True)
|
||||||
|
|
||||||
def test_set_default_vault(self):
|
|
||||||
"""Test setting default vault"""
|
|
||||||
self.cli.set_default_vault('new_vault', str(self.test_dir))
|
|
||||||
self.assertEqual(self.cli.default_vault, 'new_vault')
|
|
||||||
|
|
||||||
config = yaml.safe_load(self.cli.config_file.read_text(encoding='utf-8-sig'))
|
|
||||||
self.assertEqual(config['default_vault'], 'new_vault')
|
|
||||||
self.assertEqual(Path(config['vaults']['new_vault']), self.test_dir.resolve())
|
|
||||||
|
|
||||||
def test_create_note(self):
|
def test_create_note(self):
|
||||||
"""Test note creation"""
|
"""Test note creation"""
|
||||||
# Test basic note creation
|
# Test basic note creation
|
||||||
self.cli.create_note('test.md', 'Test content')
|
self.cli.create_note('test.md', 'Test content')
|
||||||
note_path = self.test_dir / 'test.md'
|
note_path = self.test_dir / 'test.md'
|
||||||
self.assertTrue(note_path.exists())
|
self.assertTrue(note_path.exists())
|
||||||
|
|
||||||
def test_writes_keep_lf_without_bom(self):
|
|
||||||
"""Append and frontmatter edits write LF, no BOM, even on Windows"""
|
|
||||||
note_path = self.test_dir / 'lf.md'
|
|
||||||
note_path.write_bytes(b'---\nstatus: draft\n---\n# Journal\n')
|
|
||||||
|
|
||||||
self.cli.create_note('lf.md', '### 10:00 - Entry\nline', append=True)
|
|
||||||
self.cli.frontmatter_edit('lf', ('status',), ('done',))
|
|
||||||
|
|
||||||
data = note_path.read_bytes()
|
|
||||||
self.assertNotIn(b'\r', data)
|
|
||||||
self.assertFalse(data.startswith(b'\xef\xbb\xbf'))
|
|
||||||
self.assertIn(b'status: done', data)
|
|
||||||
self.assertTrue(data.endswith(b'# Journal\n\n### 10:00 - Entry\nline'))
|
|
||||||
|
|
||||||
@unittest.skip("Method export_to_csv not implemented")
|
|
||||||
def test_export_to_csv(self):
|
|
||||||
"""Test exporting note frontmatter to CSV"""
|
|
||||||
# Create a test note with frontmatter
|
|
||||||
note_content = """---
|
|
||||||
title: Test Note
|
|
||||||
tags: [tag1, tag2]
|
|
||||||
status: in-progress
|
|
||||||
date: 2025-10-28
|
|
||||||
custom: value
|
|
||||||
---
|
|
||||||
Note content"""
|
|
||||||
self.cli.create_note('test_note.md', note_content)
|
|
||||||
|
|
||||||
# Test export with specific columns included
|
|
||||||
output_file = self.test_dir / 'output1.csv'
|
|
||||||
self.cli.export_to_csv('test_note', str(output_file), include_columns=['title', 'status', 'date'])
|
|
||||||
with open(output_file, 'r', encoding='utf-8') as f:
|
|
||||||
content = f.read().strip()
|
|
||||||
self.assertEqual(content, 'title,status,date\nTest Note,in-progress,2025-10-28')
|
|
||||||
|
|
||||||
# Test export excluding specific columns
|
|
||||||
output_file = self.test_dir / 'output2.csv'
|
|
||||||
self.cli.export_to_csv('test_note', str(output_file), exclude_columns=['tags', 'custom'])
|
|
||||||
with open(output_file, 'r', encoding='utf-8') as f:
|
|
||||||
content = f.read().strip()
|
|
||||||
self.assertEqual(content, 'title,status,date\nTest Note,in-progress,2025-10-28')
|
|
||||||
|
|
||||||
# Test export with both include and exclude (exclude takes precedence)
|
|
||||||
output_file = self.test_dir / 'output3.csv'
|
|
||||||
self.cli.export_to_csv('test_note', str(output_file),
|
|
||||||
include_columns=['title', 'status', 'date', 'custom'],
|
|
||||||
exclude_columns=['status'])
|
|
||||||
with open(output_file, 'r', encoding='utf-8') as f:
|
|
||||||
content = f.read().strip()
|
|
||||||
self.assertEqual(content, 'title,date,custom\nTest Note,2025-10-28,value')
|
|
||||||
|
|
||||||
# Test with non-existent note
|
|
||||||
with self.assertRaises(click.UsageError) as context:
|
|
||||||
self.cli.export_to_csv('non_existent', 'output.csv')
|
|
||||||
self.assertTrue("not found in vault" in str(context.exception))
|
|
||||||
|
|
||||||
# Test with note without frontmatter
|
|
||||||
self.cli.create_note('no_frontmatter.md', 'Just content')
|
|
||||||
with self.assertRaises(click.UsageError) as context:
|
|
||||||
self.cli.export_to_csv('no_frontmatter', 'output.csv')
|
|
||||||
self.assertTrue("No frontmatter found" in str(context.exception))
|
|
||||||
|
|
||||||
# Test with empty frontmatter
|
|
||||||
self.cli.create_note('empty_frontmatter.md', '---\n---\nContent')
|
|
||||||
with self.assertRaises(click.UsageError) as context:
|
|
||||||
self.cli.export_to_csv('empty_frontmatter', 'output.csv')
|
|
||||||
self.assertTrue("Empty frontmatter" in str(context.exception))
|
|
||||||
self.assertEqual(note_path.read_text(encoding='utf-8-sig'), 'Test content')
|
self.assertEqual(note_path.read_text(encoding='utf-8-sig'), 'Test content')
|
||||||
|
|
||||||
# Test note creation with auto-extension
|
# Test note creation with auto-extension
|
||||||
@@ -137,6 +65,21 @@ Note content"""
|
|||||||
'New content\nAdditional content'
|
'New content\nAdditional content'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_writes_keep_lf_without_bom(self):
|
||||||
|
"""Append and frontmatter edits write LF, no BOM, even on Windows"""
|
||||||
|
note_path = self.test_dir / 'lf.md'
|
||||||
|
note_path.write_bytes(b'---\nstatus: draft\n---\n# Journal\n')
|
||||||
|
|
||||||
|
self.cli.create_note('lf.md', '### 10:00 - Entry\nline', append=True)
|
||||||
|
self.cli.frontmatter_edit('lf', ('status',), ('done',))
|
||||||
|
|
||||||
|
data = note_path.read_bytes()
|
||||||
|
self.assertNotIn(b'\r', data)
|
||||||
|
self.assertFalse(data.startswith(b'\xef\xbb\xbf'))
|
||||||
|
self.assertIn(b'status: done', data)
|
||||||
|
self.assertTrue(data.endswith(b'# Journal\n\n### 10:00 - Entry\nline'))
|
||||||
|
|
||||||
|
|
||||||
def test_frontmatter_operations(self):
|
def test_frontmatter_operations(self):
|
||||||
"""Test frontmatter operations"""
|
"""Test frontmatter operations"""
|
||||||
# Create a test note with frontmatter
|
# Create a test note with frontmatter
|
||||||
@@ -186,8 +129,8 @@ Test content"""
|
|||||||
self.cli.frontmatter_clear(test_note, ('status,title',))
|
self.cli.frontmatter_clear(test_note, ('status,title',))
|
||||||
content = (self.test_dir / test_note).read_text(encoding='utf-8-sig')
|
content = (self.test_dir / test_note).read_text(encoding='utf-8-sig')
|
||||||
frontmatter = yaml.safe_load(content.split('---')[1])
|
frontmatter = yaml.safe_load(content.split('---')[1])
|
||||||
self.assertEqual(frontmatter['status'], '')
|
self.assertIsNone(frontmatter['status'])
|
||||||
self.assertEqual(frontmatter['title'], '')
|
self.assertIsNone(frontmatter['title'])
|
||||||
|
|
||||||
# Test frontmatter --delete
|
# Test frontmatter --delete
|
||||||
self.cli.frontmatter_delete(test_note, ('tags',))
|
self.cli.frontmatter_delete(test_note, ('tags',))
|
||||||
@@ -218,6 +161,310 @@ Test content"""
|
|||||||
link_content = (self.test_dir / 'link.md').read_text(encoding='utf-8-sig')
|
link_content = (self.test_dir / 'link.md').read_text(encoding='utf-8-sig')
|
||||||
self.assertIn('[[dest]]', link_content)
|
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')
|
||||||
|
|
||||||
|
MEETING = (
|
||||||
|
'---\n'
|
||||||
|
'type: meeting\n'
|
||||||
|
'participants:\n'
|
||||||
|
' - "[[Stéphane Charbonneau|Stéphane]]"\n'
|
||||||
|
' - "[[Haro]]"\n'
|
||||||
|
'summary: "Résumé : décisions."\n'
|
||||||
|
'---\n'
|
||||||
|
'Corps\n')
|
||||||
|
|
||||||
|
def test_frontmatter_edit_keeps_existing_list_type(self):
|
||||||
|
"""--edit on a key that is already a list writes a list, not one quoted string"""
|
||||||
|
note = self.test_dir / 'm.md'
|
||||||
|
note.write_text(self.MEETING, encoding='utf-8')
|
||||||
|
self.cli.frontmatter_edit('m', ('participants', 'type'), ('[[Jeffrey]], [[Haro]]', 'réunion, interne'))
|
||||||
|
self.assertEqual(note.read_text(encoding='utf-8'), self.MEETING
|
||||||
|
.replace(' - "[[Stéphane Charbonneau|Stéphane]]"\n - "[[Haro]]"\n',
|
||||||
|
' - "[[Jeffrey]]"\n - "[[Haro]]"\n')
|
||||||
|
.replace('type: meeting', 'type: réunion, interne'))
|
||||||
|
|
||||||
|
def test_frontmatter_add_and_remove_list_items(self):
|
||||||
|
"""Items match by link target (alias/case ignored); other items and keys untouched"""
|
||||||
|
note = self.test_dir / 'm.md'
|
||||||
|
note.write_text(self.MEETING, encoding='utf-8')
|
||||||
|
|
||||||
|
self.cli.frontmatter_list_items('m', 'participants', ('[[stéphane charbonneau]]', '[[Jeffrey]]', '[[Jeffrey|Jeff]]'))
|
||||||
|
self.cli.frontmatter_list_items('m', 'participants', ('[[Haro|H]]',), remove=True)
|
||||||
|
self.cli.frontmatter_list_items('m', 'mentioned', ('[[Livre, tome 2]]',))
|
||||||
|
self.cli.frontmatter_list_items('m', 'type', ('log',))
|
||||||
|
|
||||||
|
self.assertEqual(note.read_text(encoding='utf-8'),
|
||||||
|
'---\n'
|
||||||
|
'type:\n'
|
||||||
|
' - meeting\n'
|
||||||
|
' - log\n'
|
||||||
|
'participants:\n'
|
||||||
|
' - "[[Stéphane Charbonneau|Stéphane]]"\n'
|
||||||
|
' - "[[Jeffrey]]"\n'
|
||||||
|
'summary: "Résumé : décisions."\n'
|
||||||
|
'mentioned:\n'
|
||||||
|
' - "[[Livre, tome 2]]"\n'
|
||||||
|
'---\n'
|
||||||
|
'Corps\n')
|
||||||
|
|
||||||
|
with patch('click.echo') as echo:
|
||||||
|
self.cli.frontmatter_list_items('m', 'participants', ('[[Jeffrey|J]]',))
|
||||||
|
self.cli.frontmatter_list_items('m', 'absent', ('x',), remove=True)
|
||||||
|
self.assertEqual([c.args[0] for c in echo.call_args_list],
|
||||||
|
["No change to 'participants' in m", "No change to 'absent' in m"])
|
||||||
|
|
||||||
|
def test_frontmatter_add_refuses_invalid_yaml(self):
|
||||||
|
"""Unparseable frontmatter must not look like 'key missing' and lose existing items"""
|
||||||
|
note = self.test_dir / 'person.md'
|
||||||
|
content = '---\nchildren: "[[Julia]]", "[[Jacob]]"\ntype: person\n---\nCorps\n'
|
||||||
|
note.write_text(content, encoding='utf-8')
|
||||||
|
for remove in (False, True):
|
||||||
|
with self.assertRaises(click.UsageError):
|
||||||
|
self.cli.frontmatter_list_items('person', 'children', ('[[Nouveau]]',), remove=remove)
|
||||||
|
self.assertEqual(note.read_text(encoding='utf-8'), content)
|
||||||
|
|
||||||
|
def test_frontmatter_add_refuses_unquoted_links(self):
|
||||||
|
note = self.test_dir / 'bad.md'
|
||||||
|
content = '---\nrelated:\n - [[Haro]]\n---\n'
|
||||||
|
note.write_text(content, encoding='utf-8')
|
||||||
|
with self.assertRaises(click.UsageError):
|
||||||
|
self.cli.frontmatter_list_items('bad', 'related', ('[[Plane]]',))
|
||||||
|
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_find_note_by_name_alias_or_partial_path(self):
|
||||||
|
"""open/cat/frontmatter lookup: alias and accent-insensitive name resolve to the one
|
||||||
|
note; filename beats alias; several candidates or none raise and never guess"""
|
||||||
|
self._write_notes({
|
||||||
|
'entities/people/Mikaël Valton Charette.md': '---\naliases: [Mikaël]\n---\n',
|
||||||
|
'entities/people/Haro.md': '',
|
||||||
|
'archives/Haro.md': '',
|
||||||
|
'entities/businesses/Sécuritech.md': '',
|
||||||
|
'notes/Securitas.md': '---\naliases: [Sécuritech]\n---\n',
|
||||||
|
})
|
||||||
|
find = lambda name: self.cli._find_note(self.test_dir, name).relative_to(self.test_dir).as_posix()
|
||||||
|
self.assertEqual(find('mikael'), 'entities/people/Mikaël Valton Charette.md')
|
||||||
|
self.assertEqual(find('securitech'), 'entities/businesses/Sécuritech.md')
|
||||||
|
self.assertEqual(find('people/haro'), 'entities/people/Haro.md')
|
||||||
|
with self.assertRaisesRegex(click.UsageError, r'ambiguous[\s\S]*archives/Haro\n entities/people/Haro'):
|
||||||
|
find('Haro')
|
||||||
|
with self.assertRaisesRegex(click.UsageError, r'does not exist\. Did you mean: Securitas'):
|
||||||
|
find('Securitass')
|
||||||
|
with patch.object(OnyxCLI, '_open_uri') as open_uri:
|
||||||
|
self.cli.open_note('Mikaël')
|
||||||
|
open_uri.assert_called_once_with(
|
||||||
|
'obsidian://open?vault=test_vault&file=entities/people/Mika%C3%ABl%20Valton%20Charette.md')
|
||||||
|
|
||||||
|
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):
|
||||||
|
"""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):
|
def test_daily_note(self):
|
||||||
"""Test daily note creation"""
|
"""Test daily note creation"""
|
||||||
# Mock datetime.now() to return a specific date
|
# Mock datetime.now() to return a specific date
|
||||||
@@ -384,5 +631,20 @@ Test content"""
|
|||||||
self.assertIn(str(self.test_dir.resolve()), printed)
|
self.assertIn(str(self.test_dir.resolve()), printed)
|
||||||
self.assertNotIn('path_prefix', printed)
|
self.assertNotIn('path_prefix', printed)
|
||||||
|
|
||||||
|
def test_pipes_are_utf8_without_utf8_mode(self):
|
||||||
|
"""stdin/stdout are UTF-8 even when Python isn't in UTF-8 mode (frozen exe on Windows)"""
|
||||||
|
note = self.test_dir / 'd.md'
|
||||||
|
note.write_text('## Journal\n', encoding='utf-8')
|
||||||
|
env = {k: v for k, v in os.environ.items() if k not in ('PYTHONUTF8', 'PYTHONIOENCODING')}
|
||||||
|
home = str(self.temp_config_dir.resolve())
|
||||||
|
env.update(PYTHONUTF8='0', USERPROFILE=home, HOME=home)
|
||||||
|
result = subprocess.run([sys.executable, str(SRC), 'section', 'd', '--heading', 'Journal',
|
||||||
|
'--content', '-'], input='Réunion « test »'.encode('utf-8'),
|
||||||
|
capture_output=True, env=env)
|
||||||
|
self.assertEqual(result.returncode, 0, result.stderr)
|
||||||
|
self.assertEqual(note.read_text(encoding='utf-8'), '## Journal\nRéunion « test »\n')
|
||||||
|
printed = subprocess.run([sys.executable, str(SRC), 'print-note', 'd'], capture_output=True, env=env)
|
||||||
|
self.assertEqual(printed.stdout, '## Journal\nRéunion « test »\n\n'.encode('utf-8'))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
Reference in new issue
Block a user