upsies.uis.tui.commands.base
Abstract base class for commands
Functions
- upsies.uis.tui.commands.base.PrintText(text_getter)[source]
Print text returned by callable and exit with exit code 0
- Parameters:
text_getter – Callable that takes no arguments and returns the text to print
Classes
- class upsies.uis.tui.commands.base.CommandBase(args, config)[source]
Bases:
ABCBase class for all commands
register()must be called on all subclasses.Instead of instantiating subclasses normally, the class method
run()should be used to get instances.- Parameters:
args – Command line arguments
config –
ConfigBaseobject
- names = NotImplemented
Sequence of command names
The first name is the full name and the rest are short aliases.
- description = ''
Extended description
The class docstring is the main description. Use this class attribute to generate text programmatically.
- cli_arguments = NotImplemented
CLI argument definitions for this command
This is a
dictin which keys are option names or flags (e.g."PATH"or("--path", "-p")and each value is adictwith keyword arguments forargparse.ArgumentParser.add_argument().Additionally, you may specify a
groupin each keyword argument dictionary. Arguments with the samegroupvalue are mutually exclusive, meaning the user can only specify one of them.
- subcommands = {}
Subcommands of commands (or subsubcommands from a CLI point of view)
This is a
dictwhere keys are subcommand names and values arecli_arguments.
- subcommand_descriptions = {}
Descriptions of subcommands
For each key in
subcommands, thisdictmay provide a longer multiline (or even multiparagraph) description.
- subcommand_name = 'PLEASE_GIVE_THIS_SUBCOMMAND_A_PROPER_METAVAR'
Reference to expected subcommand in help texts
- classmethod register()[source]
Add the command and its arguments to the internal
argparse.ArgumentParserinstanceThis classmethod must be called on every subclass.
- classmethod run(args)[source]
Execute command
- Parameters:
args – Sequence of CLI arguments or None to use sys.argv
- abstract property jobs
Iterable of
JobBaseinstancesEach
JobBaseinstance may also be None for inactive jobs.
- property main_job
The main job in
jobs_activeThis job’s output is the output of the command.
In the default implementation, this is the last job in
jobs_activethatis_enabled.
- property args
Parsed CLI arguments as
argparse.Namespaceobject
- property config
Config file options as
ConfigBaseobject
- get_options(section_name, subsection_name)[source]
Combine section in config file with CLI arguments
CLI arguments take precedence unless their value is None.
- property home_directory
Passed as home_directory argument to
jobs.base.JobBaseinstances that are instantiated by this classThe default implementation passes the
CONTENTorRELEASEargument andconfig.main.cache_directorytofs.projectdir().If no
CONTENTorRELEASEargument exists, returnconfig.main.cache_directorydirectly.
- property cache_directory
Passed as cache_directory argument to
jobs.base.JobBaseinstances that are instantiated by this classThe default implementation returns
home_directory(e.g.~/.cache/upsies/Foo.2012-ASDF.upsies/) if theCONTENTorRELEASEargument exists and returnsconfig.main.cache_directoryotherwise.