rattail.commands.typer

Typer-based command utilities

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: ~typing.Annotated[~pathlib.Path, <typer.models.OptionInfo object at 0x7f5a19b0e0a0>] = 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: ~typing.Annotated[~pathlib.Path, <typer.models.OptionInfo object at 0x7f5a19b0e160>] = 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 0x7f5a19b80d90>] | None = None, list_all_models: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f5a19b80e80>] = False, list_default_models: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f5a19b80f70>] = False, make_batches: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f5a19b0b070>] = False, key: ~typing.Annotated[str, <typer.models.OptionInfo object at 0x7f5a19b0b130>] | None = None, fields: ~typing.Annotated[str, <typer.models.OptionInfo object at 0x7f5a19b0b1f0>] | None = None, exclude_fields: ~typing.Annotated[str, <typer.models.OptionInfo object at 0x7f5a19b0b2b0>] | None = None, fuzzy_fields: ~typing.Annotated[str, <typer.models.OptionInfo object at 0x7f5a19b0b370>] | None = None, fuzz_factor: ~typing.Annotated[int, <typer.models.OptionInfo object at 0x7f5a19b0b430>] = 1, create: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f5a19b0b4f0>] = True, max_create: ~typing.Annotated[int, <typer.models.OptionInfo object at 0x7f5a19b0b5b0>] | None = None, update: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f5a19b0b670>] = True, max_update: ~typing.Annotated[int, <typer.models.OptionInfo object at 0x7f5a19b0b730>] | None = None, delete: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f5a19b0b7f0>] = False, max_delete: ~typing.Annotated[int, <typer.models.OptionInfo object at 0x7f5a19b0b8b0>] | None = None, max_total: ~typing.Annotated[int, <typer.models.OptionInfo object at 0x7f5a19b0b970>] | None = None, start_date: ~typing.Annotated[~datetime.datetime, <typer.models.OptionInfo object at 0x7f5a19b0ba30>] | None = None, end_date: ~typing.Annotated[~datetime.datetime, <typer.models.OptionInfo object at 0x7f5a19b0baf0>] | None = None, year: ~typing.Annotated[int, <typer.models.OptionInfo object at 0x7f5a19b0bbb0>] | None = None, batch_size: ~typing.Annotated[int, <typer.models.OptionInfo object at 0x7f5a19b0bc70>] = 200, collect_changes: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f5a19b0bd30>] = True, warnings: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f5a19b0bdf0>] = False, max_diffs: ~typing.Annotated[int, <typer.models.OptionInfo object at 0x7f5a19b0bee0>] | None = None, dry_run: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f5a19b0bfa0>] = 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:

ctxtyper.Context instance

Returns:

RattailConfig instance

rattail.commands.typer.make_typer(**kwargs)[source]

Create a Typer command instance, per Rattail conventions.

This function is used to create the top-level rattail command, rattail_typer. You can use it to create additional top-level commands for your app, as needed.

Returns:

typer.Typer instance

rattail.commands.typer.typer_callback(ctx: ~typer.models.Context, config_paths: ~typing.Annotated[~typing.List[~pathlib.Path] | None, <typer.models.OptionInfo object at 0x7f5a19f62400>] | None = None, plus_config_paths: ~typing.Annotated[~typing.List[~pathlib.Path] | None, <typer.models.OptionInfo object at 0x7f5a19b749a0>] | None = None, progress: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f5a19b74a60>] = False, no_init: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f5a19b74af0>] = False, no_extend_config: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f5a19b80820>] = False, verbose: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f5a19b80880>] = False, progress_socket: ~typing.Annotated[str, <typer.models.OptionInfo object at 0x7f5a19b80a60>] | None = None, runas_username: ~typing.Annotated[str, <typer.models.OptionInfo object at 0x7f5a19b80b20>] | None = None, versioning: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f5a19b80c10>] = False, no_versioning: ~typing.Annotated[bool, <typer.models.OptionInfo object at 0x7f5a19b80cd0>] = 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 rattail command, 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 rattail subcommand(s), you would need to register the entry point for your module(s) containing the subcommand(s) like so (in pyproject.toml):

[project.entry-points."rattail.typer_imports"]
poser = "poser.commands"

Note that rattail.typer_imports indicates you are registering a module which defines rattail subcommands. The poser name 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 --runas command line param provides the default username.