Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion obsidianki/cli/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
"""Command handlers for ObsidianKi CLI"""
"""Command registry for ObsidianKi CLI"""

from obsidianki.cli.commands.config_cmd import COMMAND as config_command
from obsidianki.cli.commands.tag_cmd import COMMAND as tag_command
from obsidianki.cli.commands.history_cmd import COMMAND as history_command
from obsidianki.cli.commands.deck_cmd import COMMAND as deck_command
from obsidianki.cli.commands.template_cmd import COMMAND as template_command
from obsidianki.cli.commands.hide_cmd import COMMAND as hide_command
from obsidianki.cli.commands.edit_cmd import COMMAND as edit_command

ALL_COMMANDS = [
config_command,
tag_command,
history_command,
deck_command,
template_command,
hide_command,
edit_command,
]
32 changes: 32 additions & 0 deletions obsidianki/cli/commands/config_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,30 @@
from obsidianki.cli.help_utils import show_simple_help


def setup_parser(subparsers):
"""Setup argparse parser for config command"""
config_parser = subparsers.add_parser('config', help='Manage configuration', add_help=False)
config_parser.add_argument("-h", "--help", action="store_true", help="Show help message")
config_subparsers = config_parser.add_subparsers(dest='config_action', help='Config actions')

# config get <key>
get_parser = config_subparsers.add_parser('get', help='Get a configuration value')
get_parser.add_argument('key', help='Configuration key to get')

# config set <key> <value>
set_parser = config_subparsers.add_parser('set', help='Set a configuration value')
set_parser.add_argument('key', help='Configuration key to set')
set_parser.add_argument('value', help='Value to set')

# config reset
config_subparsers.add_parser('reset', help='Reset configuration to defaults')

# config where
config_subparsers.add_parser('where', help='Show configuration directory path')

return config_parser


def handle_config_command(args):
"""Handle config management commands"""

Expand Down Expand Up @@ -139,3 +163,11 @@ def handle_config_command(args):
except KeyboardInterrupt:
raise
return


# Command registration for main.py
COMMAND = {
'names': ['config'],
'setup_parser': setup_parser,
'handler': handle_config_command
}
29 changes: 29 additions & 0 deletions obsidianki/cli/commands/deck_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@
from obsidianki.cli.help_utils import show_simple_help


def setup_parser(subparsers):
"""Setup argparse parser for deck command"""
deck_parser = subparsers.add_parser('deck', help='Manage Anki decks', add_help=False)
deck_parser.add_argument("-h", "--help", action="store_true", help="Show help message")
deck_parser.add_argument("-m", "--metadata", action="store_true", help="Show metadata (card counts)")
deck_subparsers = deck_parser.add_subparsers(dest='deck_action', help='Deck actions')

# deck rename <old_name> <new_name>
rename_parser = deck_subparsers.add_parser('rename', help='Rename a deck')
rename_parser.add_argument('old_name', help='Current deck name')
rename_parser.add_argument('new_name', help='New deck name')

# deck search <deck_name> <query>
search_parser = deck_subparsers.add_parser('search', help='Search for cards in a deck')
search_parser.add_argument('deck_name', help='Deck name to search in')
search_parser.add_argument('query', help='Search query (searches front and back of cards)')
search_parser.add_argument('-l', '--limit', type=int, default=20, help='Maximum number of results to show (default: 20)')

return deck_parser


def handle_deck_command(args):
"""Handle deck management commands"""
from obsidianki.cli.services import ANKI
Expand Down Expand Up @@ -139,3 +160,11 @@ def highlight_query(text, query):
console.print(f"[dim]Showing first {limit} results. Use -l/--limit to show more.[/dim]")

return


# Command registration for main.py
COMMAND = {
'names': ['deck'],
'setup_parser': setup_parser,
'handler': handle_deck_command
}
25 changes: 25 additions & 0 deletions obsidianki/cli/commands/edit_cmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Edit mode command handler"""

from obsidianki.cli.interactive.edit_mode import edit_mode


def setup_parser(subparsers):
"""Setup argparse parser for edit command"""
edit_parser = subparsers.add_parser('edit', help='Edit existing cards', add_help=False)
edit_parser.add_argument("-h", "--help", action="store_true", help="Show help message")
edit_parser.add_argument('deck', type=str, help="Anki deck to edit cards from", nargs='?', default=None)

return edit_parser


def handle_edit_command(args):
"""Handle edit command"""
return edit_mode(args)


# Command registration for main.py
COMMAND = {
'names': ['edit'],
'setup_parser': setup_parser,
'handler': handle_edit_command
}
22 changes: 21 additions & 1 deletion obsidianki/cli/commands/hide_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,22 @@
from obsidianki.cli.help_utils import show_simple_help


def setup_parser(subparsers):
"""Setup argparse parser for hide command"""
hide_parser = subparsers.add_parser('hide', help='Manage hidden notes', add_help=False)
hide_parser.add_argument("-h", "--help", action="store_true", help="Show help message")
hide_subparsers = hide_parser.add_subparsers(dest='hide_action', help='Hide actions')

# hide unhide <note_path>
unhide_parser = hide_subparsers.add_parser('unhide', help='Unhide a specific note')
unhide_parser.add_argument('note_path', help='Path to note to unhide')

return hide_parser


def handle_hide_command(args):
"""Handle hidden notes management commands"""

# Handle help request
if args.help:
show_simple_help("Hidden Notes Management", {
"hide": "List all hidden notes",
Expand Down Expand Up @@ -43,3 +55,11 @@ def handle_hide_command(args):
else:
console.print(f"[red]Note not found in hidden list:[/red] {note_path}")
return


# Command registration for main.py
COMMAND = {
'names': ['hide'],
'setup_parser': setup_parser,
'handler': handle_hide_command
}
24 changes: 24 additions & 0 deletions obsidianki/cli/commands/history_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@
from obsidianki.cli.help_utils import show_simple_help


def setup_parser(subparsers):
"""Setup argparse parser for history command"""
history_parser = subparsers.add_parser('history', help='Manage processing history', add_help=False)
history_parser.add_argument("-h", "--help", action="store_true", help="Show help message")
history_subparsers = history_parser.add_subparsers(dest='history_action', help='History actions')

# history clear
clear_parser = history_subparsers.add_parser('clear', help='Clear processing history')
clear_parser.add_argument('--notes', nargs='+', help='Clear history for specific notes only (patterns supported)')

# history stats
history_subparsers.add_parser('stats', help='Show flashcard generation statistics')

return history_parser


def handle_history_command(args):
"""Handle history management commands"""

Expand Down Expand Up @@ -171,3 +187,11 @@ def handle_history_command(args):
except Exception as e:
console.print(f"[red]Error reading history: {e}[/red]")
return


# Command registration for main.py
COMMAND = {
'names': ['history'],
'setup_parser': setup_parser,
'handler': handle_history_command
}
34 changes: 34 additions & 0 deletions obsidianki/cli/commands/tag_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@
from obsidianki.cli.help_utils import show_simple_help


def setup_parser(subparsers):
"""Setup argparse parser for tag command"""
tag_parser = subparsers.add_parser('tag', aliases=['tags'], help='Manage tag weights', add_help=False)
tag_parser.add_argument("-h", "--help", action="store_true", help="Show help message")
tag_subparsers = tag_parser.add_subparsers(dest='tag_action', help='Tag actions')

# tag add <tag> <weight>
add_parser = tag_subparsers.add_parser('add', help='Add or update a tag weight')
add_parser.add_argument('tag', help='Tag name')
add_parser.add_argument('weight', type=float, help='Tag weight')

# tag remove <tag>
remove_parser = tag_subparsers.add_parser('remove', help='Remove a tag weight')
remove_parser.add_argument('tag', help='Tag name to remove')

# tag exclude <tag>
exclude_parser = tag_subparsers.add_parser('exclude', help='Add a tag to exclusion list')
exclude_parser.add_argument('tag', help='Tag name to exclude')

# tag include <tag>
include_parser = tag_subparsers.add_parser('include', help='Remove a tag from exclusion list')
include_parser.add_argument('tag', help='Tag name to include')

return tag_parser


def handle_tag_command(args):
"""Handle tag management commands"""

Expand Down Expand Up @@ -69,3 +95,11 @@ def handle_tag_command(args):
else:
console.print(f"[yellow]Tag '{tag}' is not in exclusion list[/yellow]")
return


# Command registration for main.py
COMMAND = {
'names': ['tag', 'tags'],
'setup_parser': setup_parser,
'handler': handle_tag_command
}
31 changes: 31 additions & 0 deletions obsidianki/cli/commands/template_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,29 @@
from obsidianki.cli.help_utils import show_simple_help


def setup_parser(subparsers):
"""Setup argparse parser for template command"""
template_parser = subparsers.add_parser('template', aliases=['templates'], help='Manage command templates', add_help=False)
template_parser.add_argument("-h", "--help", action="store_true", help="Show help message")
template_subparsers = template_parser.add_subparsers(dest='template_action', help='Template actions')

# template add <name> <command>
add_template_parser = template_subparsers.add_parser('add', help='Add a command template')
add_template_parser.add_argument('name', help='Template name')
add_template_parser.add_argument('template_command', help='Command template (without "oki" prefix)')

# template use <name> [override args...]
use_template_parser = template_subparsers.add_parser('use', help='Execute a saved template')
use_template_parser.add_argument('name', help='Template name')
use_template_parser.add_argument('override_args', nargs='...', help='Additional arguments to override template defaults')

# template remove <name>
remove_template_parser = template_subparsers.add_parser('remove', help='Remove a template')
remove_template_parser.add_argument('name', help='Template name')

return template_parser


def handle_template_command(args):
"""Handle template management commands"""

Expand Down Expand Up @@ -109,3 +132,11 @@ def handle_template_command(args):
console.print(f"[green]✓[/green] Removed template '[cyan]{name}[/cyan]'")
else:
console.print("[yellow]Cancelled[/yellow]")


# Command registration for main.py
COMMAND = {
'names': ['template', 'templates'],
'setup_parser': setup_parser,
'handler': handle_template_command
}
Loading