Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d063551a1e | ||
|
|
3d3873b699 | ||
|
|
0f763f98ed | ||
|
|
543ce76207 | ||
|
|
d77fac61c8 | ||
|
|
466fef3c23 | ||
|
|
6eb27b7cd6 | ||
|
|
43c50a889d |
No files matched your search
@@ -2,16 +2,30 @@
|
||||
|
||||
A Python-based command-line interface for interacting with Obsidian vaults. Manage notes directly from the terminal without opening Obsidian.
|
||||
|
||||
## Building the Windows Executable (.exe)
|
||||
## Building a Standalone Executable
|
||||
|
||||
You can build a standalone Windows executable using PyInstaller:
|
||||
The same `onyx.spec` builds on both Windows and Linux — PyInstaller doesn't
|
||||
cross-compile, so build natively on each platform:
|
||||
|
||||
```bash
|
||||
pip install pyinstaller
|
||||
python -m PyInstaller onyx.spec
|
||||
```
|
||||
|
||||
The resulting `onyx.exe` will be found in the `dist` folder.
|
||||
- Windows produces `dist/onyx.exe`
|
||||
- Linux produces `dist/onyx` (no extension)
|
||||
|
||||
Prebuilt binaries for both platforms are also attached to each release:
|
||||
https://gitea.mithrilforge.dev/olivier/onyx-cli/releases
|
||||
|
||||
### Installing the Linux binary
|
||||
|
||||
Drop the binary (built or downloaded) anywhere on your `PATH`:
|
||||
|
||||
```bash
|
||||
chmod +x onyx
|
||||
mv onyx ~/.local/bin/onyx # or /usr/local/bin/onyx (needs sudo)
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -94,8 +108,16 @@ onyx weekly --previous # opens last week's note
|
||||
onyx monthly --next # opens next month's note
|
||||
onyx quarterly --next # opens next quarter'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):
|
||||
- Daily: `YYYY-MM-DD.md`
|
||||
- Weekly: `YYYY-WWW.md` (ISO week, e.g. `2025-W48.md`)
|
||||
@@ -169,7 +191,8 @@ onyx print-note "note-name" --vault "vault-name"
|
||||
### Moving & Deleting Notes
|
||||
|
||||
```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"
|
||||
|
||||
# Move in specific vault
|
||||
@@ -180,7 +203,14 @@ onyx move "old-path" "new-path" --open
|
||||
|
||||
# Delete a note
|
||||
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
|
||||
onyx delete "note-path" --vault "vault-name"
|
||||
```
|
||||
@@ -201,6 +231,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 "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
|
||||
onyx frontmatter "note-name" --clear --key "tags"
|
||||
onyx frontmatter "note-name" --clear --key "date,status,tags"
|
||||
@@ -210,6 +244,62 @@ onyx frontmatter "note-name" --delete --key "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
|
||||
|
||||
```bash
|
||||
@@ -226,6 +316,8 @@ onyx --version
|
||||
- **Periodic Notes**: Support for daily, weekly, monthly, quarterly, and yearly notes
|
||||
- **Frontmatter Management**: Edit, view, clear, and delete YAML frontmatter
|
||||
- **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
|
||||
|
||||
## Requirements
|
||||
@@ -236,6 +328,8 @@ onyx --version
|
||||
|
||||
## Development
|
||||
|
||||
See [RELEASING.md](RELEASING.md) for the full version-bump/build/tag/release checklist.
|
||||
|
||||
### Running Tests
|
||||
|
||||
```bash
|
||||
|
||||
+177
@@ -0,0 +1,177 @@
|
||||
# Release procedure
|
||||
|
||||
Onyx ships as two standalone binaries (Windows `.exe`, Linux ELF) attached to a
|
||||
Gitea release — no PyPI package, no installer. This document is the checklist
|
||||
for cutting a new version.
|
||||
|
||||
## 1. Land the change
|
||||
|
||||
Implement, then verify:
|
||||
|
||||
```bash
|
||||
python -m pytest tests/ -q
|
||||
```
|
||||
|
||||
All tests must pass (skips are fine) before bumping anything.
|
||||
|
||||
## 2. Bump the version
|
||||
|
||||
The version string lives in exactly one place: the `@click.version_option`
|
||||
decorator on the `cli` group in `src/onyx.py`.
|
||||
|
||||
```python
|
||||
@click.version_option(version='X.Y.Z', prog_name='onyx')
|
||||
```
|
||||
|
||||
Use semver: patch for fixes only, minor for new commands/flags, major for
|
||||
breaking changes (removed/renamed commands, changed config schema).
|
||||
|
||||
## 3. Build both platform binaries
|
||||
|
||||
PyInstaller does **not** cross-compile — each binary must be built natively
|
||||
on its target platform.
|
||||
|
||||
**Windows** (run directly on this machine):
|
||||
```bash
|
||||
rm -rf build dist
|
||||
python -m PyInstaller onyx.spec
|
||||
# -> dist/onyx.exe
|
||||
```
|
||||
|
||||
**Linux** (via WSL, since this machine is Windows): build on WSL's native
|
||||
ext4 filesystem, not `/mnt/c/...` — PyInstaller/venvs are unreliable over
|
||||
the drvfs 9p mount.
|
||||
|
||||
```bash
|
||||
wsl -d Ubuntu-24.04 -- bash -lc '
|
||||
set -e
|
||||
rm -rf ~/onyx-build && mkdir -p ~/onyx-build
|
||||
cp -r "/mnt/c/Users/oli/Documents/o/Resources/repos/Onyx - obsidian cli tool/src" ~/onyx-build/
|
||||
cp "/mnt/c/Users/oli/Documents/o/Resources/repos/Onyx - obsidian cli tool/onyx.spec" ~/onyx-build/
|
||||
cp "/mnt/c/Users/oli/Documents/o/Resources/repos/Onyx - obsidian cli tool/requirements.txt" ~/onyx-build/
|
||||
cd ~/onyx-build
|
||||
python3 -m venv .venv
|
||||
.venv/bin/pip install -q --upgrade pip
|
||||
.venv/bin/pip install -q -r requirements.txt pyinstaller
|
||||
rm -rf build dist
|
||||
.venv/bin/pyinstaller onyx.spec
|
||||
'
|
||||
```
|
||||
|
||||
Copy the result out and rename it (Windows already produced `dist/onyx.exe`
|
||||
in the same folder, and Linux's output has no extension — rename to avoid
|
||||
any ambiguity):
|
||||
|
||||
```bash
|
||||
wsl -d Ubuntu-24.04 -- bash -lc "cp /home/oli/onyx-build/dist/onyx '/mnt/c/Users/oli/Documents/o/Resources/repos/Onyx - obsidian cli tool/dist/onyx-linux'"
|
||||
```
|
||||
|
||||
> Passing multi-line scripts to `wsl.exe` through a shell tool can mangle
|
||||
> line endings (CRLF) and silently break variable assignments. If a WSL
|
||||
> command behaves inexplicably (e.g. `command not found` for something
|
||||
> that should be a variable), write the script to a file and run that file
|
||||
> instead of an inline heredoc.
|
||||
|
||||
## 4. Verify both binaries
|
||||
|
||||
```bash
|
||||
dist/onyx.exe --version # Windows, via cmd.exe (see gotcha below)
|
||||
wsl -d Ubuntu-24.04 -- ~/onyx-build/dist/onyx --version
|
||||
```
|
||||
|
||||
Confirm the printed version matches step 2. Smoke-test at least one command
|
||||
end to end (e.g. `periodic --view`, `weekly --date 2025-11-27`) against a
|
||||
scratch vault/config — never against the real `~/.onyx-cli/config.yaml`.
|
||||
|
||||
> **Windows gotcha**: the plain bash tool can't execute a freshly built
|
||||
> `.exe` directly (`command not found`) — always invoke it through
|
||||
> `cmd.exe /c "onyx.exe ..."`.
|
||||
|
||||
## 5. Deploy locally (optional)
|
||||
|
||||
Copy the Windows build to the installed location so `onyx` on this machine
|
||||
picks up the new version immediately:
|
||||
|
||||
```bash
|
||||
cp dist/onyx.exe "/c/Users/oli/Documents/o/Resources/app back up/bin/onyx.exe"
|
||||
```
|
||||
|
||||
## 6. Commit, tag, push
|
||||
|
||||
```bash
|
||||
git add -A
|
||||
git commit -m "chore: bump to vX.Y.Z"
|
||||
|
||||
git fetch origin # someone may have committed via the Gitea web UI
|
||||
git log --oneline origin/main -3
|
||||
```
|
||||
|
||||
If `origin/main` has commits you don't have locally, **rebase, don't
|
||||
merge** (this repo's history is linear):
|
||||
|
||||
```bash
|
||||
git rebase origin/main
|
||||
```
|
||||
|
||||
Then tag (annotated, with a real changelog since the last tag) and push:
|
||||
|
||||
```bash
|
||||
git tag -a vX.Y.Z -m "vX.Y.Z
|
||||
|
||||
- ..."
|
||||
git push origin main
|
||||
git push origin vX.Y.Z
|
||||
```
|
||||
|
||||
> If you rebased *after* creating the tag, the tag still points at the
|
||||
> pre-rebase (now orphaned) commit. Delete and recreate it:
|
||||
> `git tag -d vX.Y.Z && git tag -a vX.Y.Z -m "..."` before pushing.
|
||||
|
||||
## 7. Create the Gitea release
|
||||
|
||||
`tea` hangs indefinitely under a plain non-interactive shell call, for
|
||||
*any* subcommand, including fully local ones. Always launch it as a
|
||||
supervised process (hub `start`/`wait`/`logs`), never via the bash tool
|
||||
directly.
|
||||
|
||||
Write release notes to a scratch file, then create the release with both
|
||||
assets in one call:
|
||||
|
||||
```
|
||||
tea releases create --repo olivier/onyx-cli --tag vX.Y.Z --title vX.Y.Z \
|
||||
--note-file release-notes-vX.Y.Z.md -a dist/onyx.exe -a dist/onyx-linux
|
||||
```
|
||||
|
||||
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:
|
||||
|
||||
```
|
||||
tea releases assets create --repo olivier/onyx-cli vX.Y.Z dist/<file>
|
||||
```
|
||||
|
||||
Delete the scratch release-notes file afterward — it's not a repo
|
||||
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
|
||||
|
||||
```bash
|
||||
curl -s https://gitea.mithrilforge.dev/api/v1/repos/olivier/onyx-cli/releases/tags/vX.Y.Z \
|
||||
| python -c "import json,sys; d=json.load(sys.stdin); [print(a['name'], a['size']) for a in d['assets']]"
|
||||
```
|
||||
|
||||
Confirm both `onyx.exe` and `onyx-linux` are listed with nonzero, distinct
|
||||
sizes.
|
||||
|
||||
## 9. Clean up
|
||||
|
||||
```bash
|
||||
wsl -d Ubuntu-24.04 -- bash -lc "rm -rf ~/onyx-build"
|
||||
rm -f release-notes-vX.Y.Z.md
|
||||
```
|
||||
|
||||
`dist/` and `build/` are gitignored — the binaries never get committed,
|
||||
only attached to the release.
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
|
||||
a = Analysis(
|
||||
['src\\onyx.py'],
|
||||
['src/onyx.py'],
|
||||
pathex=[],
|
||||
binaries=[],
|
||||
datas=[],
|
||||
|
||||
+639
-162
File diff suppressed because it is too large.
Load diff
+289
-65
@@ -1,3 +1,4 @@
|
||||
import json
|
||||
import os
|
||||
import unittest
|
||||
import yaml
|
||||
@@ -35,75 +36,12 @@ class TestOnyxCLI(unittest.TestCase):
|
||||
shutil.rmtree(self.test_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):
|
||||
"""Test note creation"""
|
||||
# Test basic note creation
|
||||
self.cli.create_note('test.md', 'Test content')
|
||||
note_path = self.test_dir / 'test.md'
|
||||
self.assertTrue(note_path.exists())
|
||||
|
||||
@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')
|
||||
|
||||
# Test note creation with auto-extension
|
||||
@@ -122,6 +60,21 @@ Note content"""
|
||||
(self.test_dir / 'test.md').read_text(encoding='utf-8-sig'),
|
||||
'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):
|
||||
"""Test frontmatter operations"""
|
||||
@@ -172,8 +125,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',))
|
||||
@@ -204,6 +157,277 @@ 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')
|
||||
|
||||
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_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_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):
|
||||
"""Test daily note creation"""
|
||||
# Mock datetime.now() to return a specific date
|
||||
|
||||
Reference in new issue
Block a user