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, invoke_without_command: bool = False, no_args_is_help: bool = False, subcommand_metavar: str | None = None, result_callback: Callable[[...], Any] | None = None, **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: Path, <typer.models.OptionInfo object at 0x7fe2eb4ab350>]=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: Path, <typer.models.OptionInfo object at 0x7fe2eb4ab410>]=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: List[str] | None, <typer.models.ArgumentInfo object at 0x7fe2eb4aa210>]=None, list_all_models: Annotated[bool, <typer.models.OptionInfo object at 0x7fe2ebf867d0>]=False, list_default_models: Annotated[bool, <typer.models.OptionInfo object at 0x7fe2eb4aa250>]=False, make_batches: Annotated[bool, <typer.models.OptionInfo object at 0x7fe2eb4aa310>]=False, key: Annotated[str, <typer.models.OptionInfo object at 0x7fe2eb4aa3d0>]=None, fields: Annotated[str, <typer.models.OptionInfo object at 0x7fe2eb4aa490>]=None, exclude_fields: Annotated[str, <typer.models.OptionInfo object at 0x7fe2eb4aa550>]=None, fuzzy_fields: Annotated[str, <typer.models.OptionInfo object at 0x7fe2eb4aa610>]=None, fuzz_factor: Annotated[int, <typer.models.OptionInfo object at 0x7fe2eb4aa6d0>]=1, create: Annotated[bool, <typer.models.OptionInfo object at 0x7fe2eb4aa790>]=True, max_create: Annotated[int, <typer.models.OptionInfo object at 0x7fe2eb4aa850>]=None, update: Annotated[bool, <typer.models.OptionInfo object at 0x7fe2eb4aa910>]=True, max_update: Annotated[int, <typer.models.OptionInfo object at 0x7fe2eb4aa9d0>]=None, delete: Annotated[bool, <typer.models.OptionInfo object at 0x7fe2eb4aaa90>]=False, max_delete: Annotated[int, <typer.models.OptionInfo object at 0x7fe2eb4aab50>]=None, max_total: Annotated[int, <typer.models.OptionInfo object at 0x7fe2eb4aac10>]=None, start_date: datetime, <typer.models.OptionInfo object at 0x7fe2eb4aacd0>]=None, end_date: datetime, <typer.models.OptionInfo object at 0x7fe2eb4aad90>]=None, year: Annotated[int, <typer.models.OptionInfo object at 0x7fe2eb4aae90>]=None, batch_size: Annotated[int, <typer.models.OptionInfo object at 0x7fe2eb4aaf90>]=200, collect_changes: Annotated[bool, <typer.models.OptionInfo object at 0x7fe2eb4ab050>]=True, warnings: Annotated[bool, <typer.models.OptionInfo object at 0x7fe2eb4ab110>]=False, max_diffs: Annotated[int, <typer.models.OptionInfo object at 0x7fe2eb4ab1d0>]=None, dry_run: Annotated[bool, <typer.models.OptionInfo object at 0x7fe2eb4ab290>]=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: Context, config_paths: Path] | None, <typer.models.OptionInfo object at 0x7fe2eb4a9290>]=None, plus_config_paths: Path] | None, <typer.models.OptionInfo object at 0x7fe2eb4a92d0>]=None, progress: Annotated[bool, <typer.models.OptionInfo object at 0x7fe2eb4a9390>]=False, no_init: Annotated[bool, <typer.models.OptionInfo object at 0x7fe2eb4a9450>]=False, no_extend_config: Annotated[bool, <typer.models.OptionInfo object at 0x7fe2eb4a9590>]=False, verbose: Annotated[bool, <typer.models.OptionInfo object at 0x7fe2eb4a9710>]=False, progress_socket: Annotated[str, <typer.models.OptionInfo object at 0x7fe2eb4a9890>]=None, runas_username: Annotated[str, <typer.models.OptionInfo object at 0x7fe2eb4a9a10>]=None, versioning: Annotated[bool, <typer.models.OptionInfo object at 0x7fe2eb4a9b90>]=False, no_versioning: Annotated[bool, <typer.models.OptionInfo object at 0x7fe2eb4a9d10>]=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.