rechu.command.new package

Subpackages

Submodules

rechu.command.new.input module

Input source for new subcommand.

class rechu.command.new.input.InputSource[source]

Bases: object

Abstract base class for a typed input source.

abstractmethod get_completion(text: str, state: int) str | None[source]

Retrieve a completion option for the current suggestions and text state. The text is a partial input that matches some part of the suggestions and state indicates the position of the suggestion in the sorted list of matching suggestions to choose.

If there is no match found or if the input source does not support completion suggestions, then None is returned.

abstractmethod get_date(default: datetime | None = None) datetime[source]

Retrieve a date input. The default may be used as a fallback if nothing is input or if a partial timestamp is provided.

abstractmethod get_error_output() TextIO[source]

Retrieve an output stream to write error messages to.

abstractmethod get_input(name: str, input_type: type[InputT], options: str | None = None, default: InputT | None = None) InputT[source]

Retrieve an input cast to a certain type (string, integer or float). Optionally, the input source provides suggestions from a predefined completion source defined by the options name and may fall back to a default if nothing is input.

abstractmethod get_output() TextIO[source]

Retrieve an output stream to write content to.

abstractmethod update_suggestions(suggestions: dict[str, list[str]]) None[source]

Include additional suggestion completion sources.

class rechu.command.new.input.Prompt[source]

Bases: InputSource

Standard input prompt.

EXCEPTIONS: ClassVar[dict[type[object], tuple[type[Exception], ...]]] = {<class 'rechu.types.measurable.quantity.Quantity'>: (<class 'ValueError'>, <class 'AssertionError'>)}
display_matches(substitution: str, matches: Sequence[str], longest_match_length: int) None[source]

Write a display of matches to the standard output compatible with readline buffers.

get_completion(text: str, state: int) str | None[source]

Retrieve a completion option for the current suggestions and text state. The text is a partial input that matches some part of the suggestions and state indicates the position of the suggestion in the sorted list of matching suggestions to choose.

If there is no match found or if the input source does not support completion suggestions, then None is returned.

get_date(default: datetime | None = None) datetime[source]

Retrieve a date input. The default may be used as a fallback if nothing is input or if a partial timestamp is provided.

get_error_output() TextIO[source]

Retrieve an output stream to write error messages to.

get_input(name: str, input_type: type[InputT], options: str | None = None, default: InputT | None = None) InputT[source]

Retrieve an input cast to a certain type (string, integer or float).

get_output() TextIO[source]

Retrieve an output stream to write content to.

register_readline() None[source]

Register completion method to the readline module.

update_suggestions(suggestions: dict[str, list[str]]) None[source]

Include additional suggestion completion sources.

Module contents

Subcommand to create a new receipt YAML file and import it.

final class rechu.command.new.New[source]

Bases: Base

Create a YAML file for a receipt and import it to the database.

confirm: bool
logger: logging.Logger
more: bool
run() None[source]

Execute the command.

settings: Settings
subcommand: str = 'new'
subparser_arguments: ClassVar[Iterable[tuple[str | tuple[str, ...], ArgumentKeywords]]] = [(('-c', '--confirm'), {'action': 'store_true', 'default': False, 'help': 'Confirm before updating database files or exiting'}), (('-m', '--more'), {'action': 'store_true', 'default': False, 'help': 'Allow more discounts and metadata than product items'})]
subparser_keywords: ClassVar[SubparserKeywords] = {'description': 'Interactively fill in a YAML file for a receipt and import it to the database.', 'help': 'Create receipt file and import'}