Remove test notes and finalize changes

This commit is contained in:
olivier committed 2025-11-24 08:34:28 -05:00
1 parent 7a7de7c47a
commit a7074acd91
2 files changed
+77 -47

No files matched your search

+77 -47
View File
@@ -489,7 +489,7 @@ class OnyxCLI:
note_path.write_text(new_content, encoding='utf-8-sig')
def frontmatter_edit(self, note_name: str, key: str, value: str = None, vault: str = None):
def frontmatter_edit(self, note_name: str, keys: tuple, values: tuple = None, vault: str = None):
vault_name, vault_path = self._get_vault_and_path(vault)
note_path = vault_path / note_name
if not note_path.suffix:
@@ -503,23 +503,31 @@ class OnyxCLI:
if not note_path.exists():
raise click.UsageError(f"Note {note_name} does not exist")
# Handle multiple keys
keys = [k.strip() for k in re.split(r',|\[|\]', key) if k.strip()]
updates = {}
for k in keys:
if k == 'tags':
if value:
updates[k] = value.split(',') if ',' in value else [value]
# If we have one value and multiple keys, apply value to all keys
if values and len(values) == 1 and len(keys) > 1:
values = values * len(keys)
for i, key in enumerate(keys):
# Handle comma-separated keys in a single string (legacy support)
sub_keys = [k.strip() for k in re.split(r',|\[|\]', key) if k.strip()]
value = values[i] if values and i < len(values) else None
for k in sub_keys:
if k == 'tags':
if value:
updates[k] = [t.strip() for t in value.split(',')] if ',' in value else [value.strip()]
else:
updates[k] = []
else:
updates[k] = []
else:
updates[k] = value if value is not None else ""
updates[k] = value if value is not None else ""
self._update_frontmatter(note_path, updates)
click.echo(f"Updated frontmatter for {note_name}")
def frontmatter_view(self, note_name: str, key: str, value: str = None, vault: str = None, open_file: bool = False):
def frontmatter_view(self, note_name: str, keys: tuple, value: str = None, vault: str = None, open_file: bool = False):
vault_name, vault_path = self._get_vault_and_path(vault)
note_path = vault_path / note_name
if not note_path.suffix:
@@ -536,38 +544,46 @@ class OnyxCLI:
content = note_path.read_text(encoding='utf-8-sig')
frontmatter, _, _ = self._parse_frontmatter(content)
if key not in frontmatter:
click.echo(f"Key '{key}' not found in frontmatter")
return
for key in keys:
# Handle comma-separated keys (legacy)
sub_keys = [k.strip() for k in re.split(r',|\[|\]', key) if k.strip()]
for k in sub_keys:
if k not in frontmatter:
click.echo(f"Key '{k}' not found in frontmatter")
continue
if open_file:
self._handle_open_file(frontmatter[k], vault)
continue
if open_file:
current_value = frontmatter[key]
val_str = str(current_value)
# Extract [[...]] if present
match = re.search(r'\[\[(.*?)\]\]', val_str)
if match:
target_note = match.group(1)
# Handle alias like [[Note Name|Alias]]
if '|' in target_note:
target_note = target_note.split('|')[0]
else:
target_note = val_str
self.open_note(target_note, vault=vault)
return
if value is not None:
# Check if value exists
current_value = frontmatter[k]
if isinstance(current_value, list):
result = value in current_value
else:
result = str(current_value) == value
click.echo(f"{k}: {str(result).lower()}")
else:
click.echo(yaml.dump({k: frontmatter[k]}, default_flow_style=False).strip())
if value is not None:
# Check if value exists
current_value = frontmatter[key]
if isinstance(current_value, list):
result = value in current_value
else:
result = str(current_value) == value
click.echo(str(result).lower())
def _handle_open_file(self, current_value, vault):
val_str = str(current_value)
# Extract [[...]] if present
match = re.search(r'\[\[(.*?)\]\]', val_str)
if match:
target_note = match.group(1)
# Handle alias like [[Note Name|Alias]]
if '|' in target_note:
target_note = target_note.split('|')[0]
else:
click.echo(yaml.dump({key: frontmatter[key]}, default_flow_style=False).strip())
target_note = val_str
self.open_note(target_note, vault=vault)
def frontmatter_clear(self, note_name: str, key: str, vault: str = None):
def frontmatter_clear(self, note_name: str, keys: tuple, vault: str = None):
vault_name, vault_path = self._get_vault_and_path(vault)
note_path = vault_path / note_name
if not note_path.suffix:
@@ -581,16 +597,19 @@ class OnyxCLI:
if not note_path.exists():
raise click.UsageError(f"Note {note_name} does not exist")
keys = [k.strip() for k in re.split(r',|\[|\]', key) if k.strip()]
all_keys = []
for key in keys:
all_keys.extend([k.strip() for k in re.split(r',|\[|\]', key) if k.strip()])
updates = {}
for k in keys:
for k in all_keys:
updates[k] = [] if k == 'tags' else ""
self._update_frontmatter(note_path, updates)
click.echo(f"Cleared frontmatter values for {note_name}")
def frontmatter_delete(self, note_name: str, key: str, vault: str = None):
def frontmatter_delete(self, note_name: str, keys: tuple, vault: str = None):
vault_name, vault_path = self._get_vault_and_path(vault)
note_path = vault_path / note_name
if not note_path.suffix:
@@ -607,10 +626,13 @@ class OnyxCLI:
content = note_path.read_text(encoding='utf-8-sig')
frontmatter, rest_content, _ = self._parse_frontmatter(content)
keys = [k.strip() for k in re.split(r',|\[|\]', key) if k.strip()]
all_keys = []
for key in keys:
all_keys.extend([k.strip() for k in re.split(r',|\[|\]', key) if k.strip()])
modified = False
for k in keys:
for k in all_keys:
if k in frontmatter:
del frontmatter[k]
modified = True
@@ -781,8 +803,8 @@ def delete(note_path, vault):
@click.option('--view', is_flag=True, help="View frontmatter")
@click.option('--clear', is_flag=True, help="Clear frontmatter values")
@click.option('--delete', is_flag=True, help="Delete frontmatter keys")
@click.option('--key', required=True, help="Frontmatter key to manage")
@click.option('--value', help="Value to set or check for")
@click.option('--key', required=True, multiple=True, help="Frontmatter key to manage")
@click.option('--value', multiple=True, help="Value to set or check for")
@click.option('--open', 'open_file', is_flag=True, help="Open the file referenced in the value")
@click.option('--vault', help="Vault name (if not using default)")
def frontmatter_command(note_name, edit, view, clear, delete, key, value, open_file, vault):
@@ -800,9 +822,17 @@ def frontmatter_command(note_name, edit, view, clear, delete, key, value, open_f
raise click.UsageError("Exactly one of --edit, --view, --clear, or --delete must be specified")
if edit:
if value and len(value) > 1 and len(key) != len(value):
# If we have multiple values, they must match keys count
# Unless we have 1 value, which we apply to all keys (handled in frontmatter_edit)
raise click.UsageError(f"Number of values ({len(value)}) must match number of keys ({len(key)})")
cli.frontmatter_edit(note_name, key, value, vault)
elif view:
cli.frontmatter_view(note_name, key, value, vault, open_file)
# For view, we ignore value unless it's for checking existence, which is complex with multiple keys
# For now, let's pass single value if provided, but view supports multiple keys
val = value[0] if value else None
cli.frontmatter_view(note_name, key, val, vault, open_file)
elif clear:
cli.frontmatter_clear(note_name, key, vault)
elif delete:
View File
Whitespace-only changes.