rattail.commands.typer¶
Typer-based command utilities
- class rattail.commands.typer.OrderCommands(*, name: str | None = None, commands: Dict[str, Command] | Sequence[Command] | None = None, rich_markup_mode: Literal['markdown', 'rich', None] = 'rich', rich_help_panel: str | None = None, suggest_commands: bool = True, **attrs: Any)[source]¶
Custom base class for top-level Typer command.
This exists only to ensure the commands listing is sorted when displayed with
--helpparam, since Typer “by design” will not sort them.See also this Typer doc.
- rattail.commands.typer.file_exporter_command(fn)[source]¶
Decorator for file export commands. Adds common params based on
file_exporter_command_template().
- rattail.commands.typer.file_exporter_command_template(output_dir: ~pathlib.Annotated[~pathlib.Path, <typer.models.OptionInfo object at 0x7f4c5f58ec90>] = Ellipsis)[source]¶
Stub function to provide signature for exporter commands which produce data file(s) as output. Used with
file_exporter_command().
- rattail.commands.typer.file_importer_command(fn)[source]¶
Decorator for file import commands. Adds common params based on
file_importer_command_template().
- rattail.commands.typer.file_importer_command_template(input_dir: ~pathlib.Annotated[~pathlib.Path, <typer.models.OptionInfo object at 0x7f4c5f58ed90>] = Ellipsis)[source]¶
Stub function to provide signature for importer commands which require data file(s) as input. Used with
file_importer_command().
- rattail.commands.typer.importer_command(fn)[source]¶
Decorator for import/export commands. Adds common params based on
importer_command_template().
- rattail.commands.typer.importer_command_template(models: ~typing.Annotated[~typing.List[str] | None, <typer.models.ArgumentInfo object at 0x7f4c5f58d510>] = None, list_all_models: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f4c785823d0>] = False, list_default_models: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f4c5f58d690>] = False, make_batches: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f4c5f58d790>] = False, key: ~typing.Annotated[str, <typer.models.OptionInfo object at 0x7f4c5f58d890>] = None, fields: ~typing.Annotated[str, <typer.models.OptionInfo object at 0x7f4c5f58d990>] = None, exclude_fields: ~typing.Annotated[str, <typer.models.OptionInfo object at 0x7f4c5f58da90>] = None, fuzzy_fields: ~typing.Annotated[str, <typer.models.OptionInfo object at 0x7f4c5f58db90>] = None, fuzz_factor: ~typing.Annotated[int, <typer.models.OptionInfo object at 0x7f4c5f58dc90>] = 1, create: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f4c5f58dd90>] = True, max_create: ~typing.Annotated[int, <typer.models.OptionInfo object at 0x7f4c5f58de90>] = None, update: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f4c5f58df90>] = True, max_update: ~typing.Annotated[int, <typer.models.OptionInfo object at 0x7f4c5f58e090>] = None, delete: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f4c5f58e190>] = False, max_delete: ~typing.Annotated[int, <typer.models.OptionInfo object at 0x7f4c5f58e290>] = None, max_total: ~typing.Annotated[int, <typer.models.OptionInfo object at 0x7f4c5f58e390>] = None, start_date: ~datetime.Annotated[~datetime.datetime, <typer.models.OptionInfo object at 0x7f4c5f58e490>] = None, end_date: ~datetime.Annotated[~datetime.datetime, <typer.models.OptionInfo object at 0x7f4c5f58e590>] = None, year: ~typing.Annotated[int, <typer.models.OptionInfo object at 0x7f4c5f58e690>] = None, batch_size: ~typing.Annotated[int, <typer.models.OptionInfo object at 0x7f4c5f58e790>] = 200, collect_changes: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f4c5f58e890>] = True, warnings: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f4c5f58e990>] = False, max_diffs: ~typing.Annotated[int, <typer.models.OptionInfo object at 0x7f4c5f58ea90>] = None, dry_run: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f4c5f58eb90>] = False)[source]¶
Stub function which provides a common param signature; used with
importer_command().
- rattail.commands.typer.make_cli_config(ctx)[source]¶
Make a config object according to the command-line context (params).
- Parameters:
ctx¶ –
typer.Contextinstance- Returns:
RattailConfiginstance
- rattail.commands.typer.make_typer(**kwargs)[source]¶
Create a Typer command instance, per Rattail conventions.
This function is used to create the top-level
rattailcommand,rattail_typer. You can use it to create additional top-level commands for your app, as needed.- Returns:
typer.Typerinstance
- rattail.commands.typer.typer_callback(ctx: ~typer.models.Context, config_paths: ~typing.Annotated[~typing.List[~pathlib.Path] | None, <typer.models.OptionInfo object at 0x7f4c5f55eb50>] = None, plus_config_paths: ~typing.Annotated[~typing.List[~pathlib.Path] | None, <typer.models.OptionInfo object at 0x7f4c5f58c390>] = None, progress: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f4c5f58cd50>] = False, no_init: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f4c5f58ce10>] = False, no_extend_config: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f4c5f58cf10>] = False, verbose: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f4c5f58d010>] = False, progress_socket: ~typing.Annotated[str, <typer.models.OptionInfo object at 0x7f4c5f58d110>] = None, runas_username: ~typing.Annotated[str, <typer.models.OptionInfo object at 0x7f4c5f58d210>] = None, versioning: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f4c5f58d310>] = False, no_versioning: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f4c5f58d410>] = False)[source]¶
Generic callback for use with top-level commands.
- rattail.commands.typer.typer_eager_imports(group: [<class 'typer.main.Typer'>, <class 'str'>])[source]¶
Eagerly import all modules which are registered as having subcommands belonging to the given group.
This is used to locate subcommands which may be defined by multiple different packages. It is mostly needed for the main
rattailcommand, since e.g. various POS integration packages may define additional subcommands for it.Most custom apps will define their own top-level command and some subcommands, but will have no need to “discover” additional subcommands defined elsewhere. Hence you normally would not need to call this function.
However if you wish to define a
rattailsubcommand(s), you would need to register the entry point for your module(s) containing the subcommand(s) like so (inpyproject.toml):[project.entry-points."rattail.typer_imports"] poser = "poser.commands"
Note that
rattail.typer_importsindicates you are registering a module which definesrattailsubcommands. Theposername is arbitrary but should match your package name.- Parameters:
group¶ – Typer group command, or the name of one.
- rattail.commands.typer.typer_get_runas_user(ctx, session=None)[source]¶
Convenience function to get the “runas” User object for the current command.
Uses
rattail.app.AppHandler.get_runas_user()under the hood, but the--runascommand line param provides the default username.