CLI Hooks#
These hooks are specific to Moe’s commandline interface.
CLI#
- class Hooks#
General CLI hook specifications.
- static add_command(cmd_parsers: _SubParsersAction)#
Add a sub-command to Moe’s CLI.
- Parameters:
cmd_parsers – Contains all the sub-command parsers. The new sub-command should be added as an argparse parser to cmd_parsers.
Example
Inside your hook implementation:
my_parser = cmd_parsers.add_parser('<command_name>', help='') my_parser.add_argument('bar', type=int) my_parser.set_defaults(func=my_function)
Important
To specify a function to run when your command is passed, you need to define the
func
key usingset_defaults
as shown above. The function will be called like:func( session: sqlalchemy.orm.session.Session, # library db session args: argparse.Namespace, # parsed commandline arguments )
Note
If your command utilizes a query, you can specify
query_parser
as a parent parser:edit_parser = cmd_parsers.add_parser( "list", description="Lists music in the library.", parents=[moe.cli.query_parser], )
Then, you can call
query.query(args.query, query_type=args.query_type)
to get a list of items matching the query from the library.See also
The
query()
function.
Plugins#
Import#
- class Hooks#
Import plugin cli hook specifications.
- static add_candidate_prompt_choice(prompt_choices: list[PromptChoice])#
Add a user input choice to the candidate prompt.
func
will be supplied the following keyword arguments:new_album
: Album being added to the library.candidates
: Candidate albums with all the import changes.
- Parameters:
prompt_choices – List of prompt choices. To add a prompt choice, simply append it to this list.
Example
prompt_choices.append( PromptChoice( title="Abort", shortcut_key="x", func=_abort_changes ) )
- static add_import_prompt_choice(prompt_choices: list[PromptChoice])#
Add a user input choice to the import prompt.
func
will be supplied the following keyword arguments:new_album
: Album being added to the library.candidate
: Candidate album with all the import changes.
- Parameters:
prompt_choices – List of prompt choices. To add a prompt choice, simply append it to this list.
Example
prompt_choices.append( PromptChoice( title="Abort", shortcut_key="x", func=_abort_changes ) )