From e7304b840ea6fe1cde92a2b8b8b8db8fe25cb635 Mon Sep 17 00:00:00 2001 From: Olivier Date: Sat, 22 Nov 2025 16:13:20 -0500 Subject: [PATCH] feat: Implement core Onyx CLI logic in `src/onyx.py`, remove various test scripts, and update `README.md`. --- .onyx-cli-test/config.yaml | 3 - README.md | 1 + reproduce_extension.py | 83 --------------------------- reproduce_issue.py | 62 -------------------- src/__pycache__/onyx.cpython-312.pyc | Bin 36053 -> 39555 bytes src/onyx.py | 57 +++++++++++++++++- temp_home/.onyx-cli/config.yaml | 3 - test_config.yaml | 3 - test_exe.py | 48 ---------------- test_home/.onyx-cli/config.yaml | 3 - test_newline.py | 55 ------------------ test_vault_newline/newline_test.md | 2 - 12 files changed, 55 insertions(+), 265 deletions(-) delete mode 100644 .onyx-cli-test/config.yaml delete mode 100644 reproduce_extension.py delete mode 100644 reproduce_issue.py delete mode 100644 temp_home/.onyx-cli/config.yaml delete mode 100644 test_config.yaml delete mode 100644 test_exe.py delete mode 100644 test_home/.onyx-cli/config.yaml delete mode 100644 test_newline.py delete mode 100644 test_vault_newline/newline_test.md diff --git a/.onyx-cli-test/config.yaml b/.onyx-cli-test/config.yaml deleted file mode 100644 index 4f1f5cd..0000000 --- a/.onyx-cli-test/config.yaml +++ /dev/null @@ -1,3 +0,0 @@ -default_vault: test -vaults: - test: C:/Users/oli/Documents/o/Resources/repos/Onyx - obsidian cli tool/test_vault_newline \ No newline at end of file diff --git a/README.md b/README.md index ec50b5d..815b22a 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,7 @@ onyx --version - **Vault Management**: Set and switch between multiple Obsidian vaults - **Note Operations**: Create, open, move, rename, and delete notes +- **Templates**: Support for Core Templates and Templater - **Recursive Search**: Find notes in nested directories - **Periodic Notes**: Support for daily, weekly, monthly, quarterly, and yearly notes - **Frontmatter Management**: Edit, view, clear, and delete YAML frontmatter diff --git a/reproduce_extension.py b/reproduce_extension.py deleted file mode 100644 index 47705bf..0000000 --- a/reproduce_extension.py +++ /dev/null @@ -1,83 +0,0 @@ -import sys -from pathlib import Path -# Add src to path -sys.path.append(str(Path.cwd() / 'src')) -from onyx import OnyxCLI -import shutil - -def test_extension_logic(): - # Setup - test_dir = Path('reproduce_test_vault') - if test_dir.exists(): - shutil.rmtree(test_dir) - test_dir.mkdir() - - # We need to set a default vault for the CLI to work without error - # Since we can't easily inject config without mocking, we'll rely on the fact that - # create_note calls _get_vault_and_path. - # We will mock the config file path or just use the class methods that don't require it if possible, - # but create_note DOES require it. - - # Let's just instantiate CLI and manually set the vault path in the internal config if needed, - # or better, just use the public method set_default_vault to configure our test vault. - - cli = OnyxCLI() - try: - cli.set_default_vault('reproduce_vault', str(test_dir.resolve())) - except Exception as e: - print(f"Setup warning: {e}") - - # Test 1: No extension - print("Test 1: 'note1' -> should be 'note1.md'") - try: - cli.create_note('note1', 'content') - if (test_dir / 'note1.md').exists(): - print("PASS: note1.md created") - else: - print("FAIL: note1.md NOT created") - except Exception as e: - print(f"FAIL: Test 1 error: {e}") - - # Test 2: With .md extension - print("\nTest 2: 'note2.md' -> should be 'note2.md'") - try: - cli.create_note('note2.md', 'content') - if (test_dir / 'note2.md').exists() and not (test_dir / 'note2.md.md').exists(): - print("PASS: note2.md created correctly") - else: - print("FAIL: note2.md handling incorrect") - except Exception as e: - print(f"FAIL: Test 2 error: {e}") - - # Test 3: With other extension (potential issue) - print("\nTest 3: 'note3.txt' -> should be 'note3.txt.md' (assuming user intent)") - try: - cli.create_note('note3.txt', 'content') - if (test_dir / 'note3.txt.md').exists(): - print("PASS: note3.txt.md created") - elif (test_dir / 'note3.txt').exists(): - print("FAIL: created note3.txt instead of note3.txt.md") - else: - print("FAIL: unexpected result for note3.txt") - except Exception as e: - print(f"FAIL: Test 3 error: {e}") - - # Test 4: Nested folders - print("\nTest 4: 'folder/nested/note' -> should create folders") - try: - cli.create_note('folder/nested/note', 'content') - if (test_dir / 'folder' / 'nested' / 'note.md').exists(): - print("PASS: Nested folders created") - else: - print("FAIL: Nested folders NOT created") - except Exception as e: - print(f"FAIL: Test 4 error: {e}") - - # Cleanup - try: - shutil.rmtree(test_dir) - except: - pass - -if __name__ == "__main__": - test_extension_logic() diff --git a/reproduce_issue.py b/reproduce_issue.py deleted file mode 100644 index 0080140..0000000 --- a/reproduce_issue.py +++ /dev/null @@ -1,62 +0,0 @@ -import sys -from pathlib import Path -import subprocess -import os -import shutil - -# Clean up previous test vault -vault_path = Path("test_vault").resolve() -if vault_path.exists(): - shutil.rmtree(vault_path) -vault_path.mkdir(exist_ok=True) - -# Create a note with French characters manually -note_name = "french_test.md" -note_path = vault_path / note_name -content = "C'est l'été à Paris. Ça va bien?" - -# Write with default encoding (likely cp1252 on Windows or utf-8) -try: - # Write as UTF-8 (no BOM) to simulate a "good" file - note_path.write_text(content, encoding="utf-8") - print(f"Created {note_name} with utf-8") -except Exception as e: - print(f"Error creating note: {e}") - -# Import OnyxCLI -sys.path.append(str(Path("src").resolve())) -from onyx import OnyxCLI - -cli = OnyxCLI() -# Mock config to point to our test vault -cli.config_file = Path("test_config.yaml").resolve() -cli.config_file.write_text(f"default_vault: test\nvaults:\n test: {str(vault_path).replace(os.sep, '/')}", encoding="utf-8") - -print("\n--- Reading note with OnyxCLI ---") -try: - # This calls read_text() internally. - # With our fix (utf-8-sig), it should read utf-8 (no BOM) correctly too. - cli.print_note(note_name, vault="test") -except Exception as e: - print(f"Error reading note: {e}") - -print("\n--- Creating note with OnyxCLI ---") -new_note_name = "french_cli_created.md" -new_content = "Hélène et François" -try: - cli.create_note(new_note_name, content=new_content, vault="test", overwrite=True) - # Check how it was saved - saved_path = vault_path / new_note_name - # Read as bytes to check for BOM - raw_bytes = saved_path.read_bytes() - print(f"Saved bytes: {raw_bytes}") - - if raw_bytes.startswith(b'\xef\xbb\xbf'): - print("SUCCESS: BOM detected") - else: - print("FAILURE: No BOM detected") - - # Try reading it back with utf-8-sig (which handles BOM) - print(f"Content read back as utf-8-sig: {saved_path.read_text(encoding='utf-8-sig')}") -except Exception as e: - print(f"Error creating/checking note: {e}") diff --git a/src/__pycache__/onyx.cpython-312.pyc b/src/__pycache__/onyx.cpython-312.pyc index 193640d1ea3657d90bd9acfddd2935ccfdf7dbcd..76dd12efdf0a29e97b79cdb042c0e2ccf418e618 100644 GIT binary patch delta 6976 zcmbVQYjjgrcE0Ccy=B?5B|l{OAwRGz{Kf_wgAIOQut`h+CqQ^O#`hXzY}q-I0ShUD zB$OnRX&|Rrgr*FhChd@cHY7@>?vKt2lg?UXvbsi!ow1|EbZD9;ndw^83~4iq&SJXv zy^?So_*2>X?m7E$_Bs3Pv-i>cZTO?FmBCJ+Z$V`F>6bsdrmmQZ> z?53vpWwn{Ts97ykCk0YTjjU|e+DI*1uHC@SYM)|fRK@z$Vu9FvdCesOhZ5F`Ev!YA?4Z=h(q&_1X5$L**Ptbv!3!UQ#B{5pI%9 z64wT{U%$za7AM|rX7B22$tw0A`Za(>hOCfikhEf|q!HCp`jAFUdsg*$hD=jSdP!>o z#UYhw2C7BR={d1cOb6Kv`0C(mkJ15N?RmW7hSP9PP^D^p7b$suW^q9Gx^{&JXeu~-J4a!C%D@N(#v zh^u8&6)-|&d=#Bn1*4RT%}Y6AHJCMsHNagKpCan%q;(o_dM%L4zC}iA9Z;R(3J_Dv zj;sfxEqm|HhO=?|h!aq0uHkG^?ek=FaM)ENGewj+c%LRx?{6>gy9x*5c1h%!q$|8MwflLZ4l2t??CLg!54>wp-gQ@@@ zP#xyBb0wUQXD7Dgg?#b>!k8LPLHzb-h%e=+K)7Apq;P~gD(vEp5SPa9>^LY59&)&c z90QKQvC+{9kJ~rtP^RZ_dmWNzVE>3DR?|ip&YzVOsZvC|)x+K~PZxD?T!^DZAmh@~ zW$>V#2pbS85xM|ksu8!>7gM`EqIA@yra8#4BJ4u0ad6BtHo=cqWf_Jk(wN9j5pSD0w{q$GIC>j;S@#tm;TzcQmW} zIpcgTjni! zQ)v-PO(dn}57*7sIdf^$T>6Gs^`qe*4oA}Je$NrT?Nb;>fae`=I@o-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yu|20d)w%6zN_M)#tiHN8;B=`fmbJpGu;ldzdn^SZ>4V33z;gV3)63H>_UxWOrgc!}6;s*LB{Exmr=rZ!+P? zBCPAJVNb(I?^^jX3%}M|XmQP43yS_R!6y}~yj`r@l%nf`%P0Fi($1*Z4=M4d6SWITdOL7P9=Xe;`q2VHnw; zwI&M(1?XaOyLmQw2_g)oMsAYMz1-WW`?~QiY!a11?TGZp#I$1@A5-2;EWThb<|++4 z5Pp0AD#m)Cbf`r=fRY=W4v^F6_0%cur@h?M3}Zv>*;c*+)h$g;O{&~NzZO+#L82TI z4=iAU}lYr{M*#P|WKpxu;8KL3j(pt8jUEZ{1N^x1|Kh}0d z!q2lc;xpMOK9}h-hQA#iD;7&O)8+!%5Im0a z<4fV0dsnh5n7VfnV)>Cuwhh{k$UB84{zJ_^6!O^AvBId+Rbu~iJ4`A+34upUoS$*a*|M4FlfIrq(0E?L^3b%P7q z57ony_th1M23$ntL(}MX6HQ>dlO%cg!2FCIOj#S zl@Jf}Z0k_{mJBQ4TK-LXpWjBK2|kjc<3veLA@SmHY@`{xiOnPUE}S|si#-9)pQy7r zNl*zNoyZ@iZDDqQ57{pxpq>;>C%Q_sjaVr2AfQ^ANmFV@0+uh}>G$Eu6vU62P%+ue z*roR6c&hI8>bLL?)Z)JsxL|>YPFBUQbg+skiSWw0l<*rT=g77x*}*n4$T_825|DyV MPgRBoPQ}ar0jOa9y#N3J diff --git a/src/onyx.py b/src/onyx.py index 2dde401..37b2d71 100644 --- a/src/onyx.py +++ b/src/onyx.py @@ -146,13 +146,63 @@ class OnyxCLI: click.echo(f"Default vault: {self.default_vault}") click.echo(f"Path: {vault_path}") + def _get_template_folder(self, vault_path: Path) -> Optional[Path]: + """ + Get template folder path from Templater plugin (if enabled), + falling back to core Templates plugin. + """ + # Try Templater plugin first + templater_config = vault_path / ".obsidian" / "plugins" / "templater-obsidian" / "data.json" + if templater_config.exists(): + try: + config = json.loads(templater_config.read_text(encoding='utf-8-sig')) + folder = config.get('templates_folder') + if folder: + return vault_path / folder + except (json.JSONDecodeError, KeyError): + pass + + # Fall back to core Templates plugin + templates_config = vault_path / ".obsidian" / "templates.json" + if templates_config.exists(): + try: + config = json.loads(templates_config.read_text(encoding='utf-8-sig')) + folder = config.get('folder') + if folder: + return vault_path / folder + except (json.JSONDecodeError, KeyError): + pass + + return None + def create_note(self, note_name: str, content: str = "", vault: str = None, - overwrite: bool = False, append: bool = False, open_after: bool = False): + overwrite: bool = False, append: bool = False, open_after: bool = False, template: str = None): vault_name, vault_path = self._get_vault_and_path(vault) note_path = vault_path / note_name if not str(note_path).endswith('.md'): note_path = Path(str(note_path) + '.md') + if template: + template_folder = self._get_template_folder(vault_path) + if template_folder: + template_path = template_folder / template + if not template_path.suffix: + template_path = template_path.with_suffix('.md') + + if template_path.exists(): + template_content = template_path.read_text(encoding='utf-8-sig') + if content: + content = template_content + '\n' + content + else: + content = template_content + + # Open by default if template is used + open_after = True + else: + click.echo(f"Warning: Template '{template}' not found at {template_path}") + else: + click.echo("Warning: Template folder not configured") + note_path.parent.mkdir(parents=True, exist_ok=True) if note_path.exists(): @@ -683,7 +733,8 @@ def yearly(vault): @click.option('--overwrite', is_flag=True, help="Overwrite existing note") @click.option('--append', is_flag=True, help="Append to existing note") @click.option('--open', 'open_after', is_flag=True, help="Open note after creation") -def create(note_name, content, vault, overwrite, append, open_after): +@click.option('--template', help="Template to use") +def create(note_name, content, vault, overwrite, append, open_after, template): """Create or modify a note in the vault USAGE: @@ -692,7 +743,7 @@ def create(note_name, content, vault, overwrite, append, open_after): """ if content: content = content.replace('\\n', '\n') - OnyxCLI().create_note(note_name, content, vault, overwrite, append, open_after) + OnyxCLI().create_note(note_name, content, vault, overwrite, append, open_after, template) @cli.command() @click.argument('note_name') diff --git a/temp_home/.onyx-cli/config.yaml b/temp_home/.onyx-cli/config.yaml deleted file mode 100644 index e1f4bf5..0000000 --- a/temp_home/.onyx-cli/config.yaml +++ /dev/null @@ -1,3 +0,0 @@ -default_vault: test -vaults: - test: C:/Users/oli/Documents/o/Resources/repos/Onyx - obsidian cli tool/test_vault_exe \ No newline at end of file diff --git a/test_config.yaml b/test_config.yaml deleted file mode 100644 index 1b13b61..0000000 --- a/test_config.yaml +++ /dev/null @@ -1,3 +0,0 @@ -default_vault: test -vaults: - test: C:/Users/oli/Documents/o/Resources/repos/Onyx - obsidian cli tool/test_vault \ No newline at end of file diff --git a/test_exe.py b/test_exe.py deleted file mode 100644 index e5a2a34..0000000 --- a/test_exe.py +++ /dev/null @@ -1,48 +0,0 @@ -import subprocess -import shutil -from pathlib import Path -import sys - -def test_exe(): - exe_path = Path('dist/onyx.exe').resolve() - if not exe_path.exists(): - print(f"Executable not found at {exe_path}") - sys.exit(1) - - test_dir = Path('test_vault_exe') - if test_dir.exists(): - shutil.rmtree(test_dir) - test_dir.mkdir() - - print(f"Testing executable: {exe_path}") - - # Set default vault - cmd = [str(exe_path), 'set-default', 'test_vault_exe', '--path', str(test_dir.resolve())] - print(f"Running: {' '.join(cmd)}") - subprocess.run(cmd, check=True) - - # Create note without extension - cmd = [str(exe_path), 'create', 'exe_note1', '--content', 'content'] - print(f"Running: {' '.join(cmd)}") - subprocess.run(cmd, check=True) - - if (test_dir / 'exe_note1.md').exists(): - print("PASS: exe_note1.md created") - else: - print("FAIL: exe_note1.md NOT created") - - # Create note with .txt extension - cmd = [str(exe_path), 'create', 'exe_note2.txt', '--content', 'content'] - print(f"Running: {' '.join(cmd)}") - subprocess.run(cmd, check=True) - - if (test_dir / 'exe_note2.txt.md').exists(): - print("PASS: exe_note2.txt.md created") - else: - print("FAIL: exe_note2.txt.md NOT created") - - # Cleanup - shutil.rmtree(test_dir) - -if __name__ == "__main__": - test_exe() diff --git a/test_home/.onyx-cli/config.yaml b/test_home/.onyx-cli/config.yaml deleted file mode 100644 index 4f1f5cd..0000000 --- a/test_home/.onyx-cli/config.yaml +++ /dev/null @@ -1,3 +0,0 @@ -default_vault: test -vaults: - test: C:/Users/oli/Documents/o/Resources/repos/Onyx - obsidian cli tool/test_vault_newline \ No newline at end of file diff --git a/test_newline.py b/test_newline.py deleted file mode 100644 index 446b640..0000000 --- a/test_newline.py +++ /dev/null @@ -1,55 +0,0 @@ -import sys -from pathlib import Path -sys.path.append(str(Path("src").resolve())) -from click.testing import CliRunner -from onyx import cli -import os - -# Setup test vault -vault_path = Path("test_vault_newline").resolve() -if vault_path.exists(): - import shutil - shutil.rmtree(vault_path) -vault_path.mkdir(exist_ok=True) - -# Create config -config_dir = Path(".onyx-cli-test") -config_dir.mkdir(exist_ok=True) -config_file = config_dir / "config.yaml" -config_file.write_text(f"default_vault: test\nvaults:\n test: {str(vault_path).replace(os.sep, '/')}", encoding="utf-8") - -# Mock the config path in OnyxCLI (we need to monkeypatch or just rely on the fact that we can't easily change the class attribute globally without reloading, -# but wait, OnyxCLI is instantiated inside the commands. -# I'll just monkeypatch OnyxCLI.__init__ to use my config file for this test, or better, just set the env var if supported? -# The code uses Path.home() / '.onyx-cli' / 'config.yaml'. -# I'll monkeypatch Path.home to return my local dir. - -from unittest.mock import patch - -with patch("pathlib.Path.home", return_value=Path.cwd() / "test_home"): - # Setup home dir - home = Path.cwd() / "test_home" - (home / ".onyx-cli").mkdir(parents=True, exist_ok=True) - (home / ".onyx-cli" / "config.yaml").write_text(f"default_vault: test\nvaults:\n test: {str(vault_path).replace(os.sep, '/')}", encoding="utf-8") - - runner = CliRunner() - - print("--- Testing with literal \\n ---") - result = runner.invoke(cli, ['create', 'newline_test', '--content', 'Line1\\nLine2', '--vault', 'test']) - - if result.exit_code != 0: - print(f"Command failed: {result.output}") - else: - note_path = vault_path / "newline_test.md" - if note_path.exists(): - content = note_path.read_text(encoding='utf-8-sig') - print(f"Content length: {len(content)}") - print(f"Content repr: {repr(content)}") - if '\n' in content and '\\n' not in content: - print("Result: Real newline found") - elif '\\n' in content: - print("Result: Literal \\n found") - else: - print("Result: Unexpected content") - else: - print("Note not created") diff --git a/test_vault_newline/newline_test.md b/test_vault_newline/newline_test.md deleted file mode 100644 index 057ec59..0000000 --- a/test_vault_newline/newline_test.md +++ /dev/null @@ -1,2 +0,0 @@ -Line1 -Line2 \ No newline at end of file