Skip to content

Commit 533c63e

Browse files
committed
feat: add apy list-models
refer: #121
1 parent 1ee6afe commit 533c63e

File tree

3 files changed

+44
-27
lines changed

3 files changed

+44
-27
lines changed

completion/_apy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ _apy() {
5454
'info:Print some basic statistics' \
5555
'list-cards:List cards that match QUERY' \
5656
'list-cards-table:List cards that match QUERY in table format' \
57+
'list-models:List available models' \
5758
'list-notes:List notes that match QUERY' \
5859
'model:Interact with the models' \
5960
'reposition:Reposition new cards that match QUERY' \
@@ -129,6 +130,10 @@ _apy() {
129130
'(-l --show-lapses)'{-l,--show-lapses}'[Display card number of lapses]' \
130131
$opts_help \
131132
);;
133+
list-models)
134+
opts=( \
135+
$opts_help \
136+
);;
132137
list-notes)
133138
opts=( \
134139
'::Query' \

src/apyanki/anki.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,11 @@ def list_cards_as_table(self, query: str, opts_display: dict[str, bool]) -> None
470470

471471
console.print(table)
472472

473+
def list_models(self) -> None:
474+
"""List available models"""
475+
for name in self.model_names:
476+
console.print(name)
477+
473478
def add_notes_with_editor(
474479
self,
475480
tags: str = "",

src/apyanki/cli.py

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -397,33 +397,6 @@ def list_cards(query: str, verbose: bool) -> None:
397397
a.list_cards(query, verbose)
398398

399399

400-
@main.command("list-notes")
401-
@click.argument("query", required=False, nargs=-1)
402-
@click.option("-c", "--show-cards", is_flag=True, help="Print card specs")
403-
@click.option("-r", "--show-raw-fields", is_flag=True, help="Print raw field data")
404-
@click.option("-v", "--verbose", is_flag=True, help="Print note details")
405-
def list_notes(
406-
query: str, show_cards: bool, show_raw_fields: bool, verbose: bool
407-
) -> None:
408-
"""List notes that match QUERY.
409-
410-
The default QUERY is "tag:marked OR -flag:0". This default can be
411-
customized in the config file `~/.config/apy/apy.json`, e.g. with
412-
413-
\b
414-
{
415-
"query": "tag:marked OR tag:leech"
416-
}
417-
"""
418-
if query:
419-
query = " ".join(query)
420-
else:
421-
query = cfg["query"]
422-
423-
with Anki(**cfg) as a:
424-
a.list_notes(query, show_cards, show_raw_fields, verbose)
425-
426-
427400
@main.command("list-cards-table")
428401
@click.argument("query", required=False, nargs=-1)
429402
@click.option("-a", "--show-answer", is_flag=True, help="Display answer")
@@ -473,6 +446,40 @@ def list_cards_table(
473446
)
474447

475448

449+
@main.command("list-models")
450+
def list_models() -> None:
451+
"""List available models."""
452+
with Anki(**cfg) as a:
453+
a.list_models()
454+
455+
456+
@main.command("list-notes")
457+
@click.argument("query", required=False, nargs=-1)
458+
@click.option("-c", "--show-cards", is_flag=True, help="Print card specs")
459+
@click.option("-r", "--show-raw-fields", is_flag=True, help="Print raw field data")
460+
@click.option("-v", "--verbose", is_flag=True, help="Print note details")
461+
def list_notes(
462+
query: str, show_cards: bool, show_raw_fields: bool, verbose: bool
463+
) -> None:
464+
"""List notes that match QUERY.
465+
466+
The default QUERY is "tag:marked OR -flag:0". This default can be
467+
customized in the config file `~/.config/apy/apy.json`, e.g. with
468+
469+
\b
470+
{
471+
"query": "tag:marked OR tag:leech"
472+
}
473+
"""
474+
if query:
475+
query = " ".join(query)
476+
else:
477+
query = cfg["query"]
478+
479+
with Anki(**cfg) as a:
480+
a.list_notes(query, show_cards, show_raw_fields, verbose)
481+
482+
476483
@main.command()
477484
@click.argument("query", required=False, nargs=-1)
478485
@click.option(

0 commit comments

Comments
 (0)