CLI
elva.cli
Module providing the main command line interface functionality.
Functions:
-
warn–Emit a warning to stderr.
-
get_composed_decorator–Compose a decorator out of many.
-
get_data_file_path–Ensure a correct and resolved data file path.
-
derive_stem–Derive the data file stem.
-
get_render_file_path–Derive the render file path from the path to a data file.
-
get_log_file_path–Derive the log file path from the path to a data file.
-
read_data_file–Get metadata from file as parameter mapping.
-
read_config_files–Get parameters defined in configuration files.
-
merge_configs–Update the user-defined parameters with parameters from files.
-
find_default_config_paths–CLI default callback finding config files from highest to lowest precedence.
-
resolve_verbosity–CLI callback converting counts of verbosity flags to log level names.
-
resolve_data_file_path–CLI callback ensuring a correct and resolved data file path.
-
pass_config_for–Configure the
pass_configdecorator to respect theapptable in configurations.
Attributes:
-
PATH_TYPE–Default type of path parameters in the CLI API.
-
LEVEL–Logging level sorted by verbosity.
-
pass_config(Callable) –Command decorator passing the merged configuration dictionary as the first positional argument to a
Command. -
configs_option–A CLI command decorator defining an option for exclusive config file paths.
-
additional_configs_option–A CLI command decorator defining an option for additional config file paths.
-
verbosity_option–A CLI command decorator defining an option for log verbosity.
-
log_file_path_option–A CLI command decorator defining an option for log file path.
-
display_name_option–A CLI command decorator defining an option for the display name.
-
user_name_option–A CLI command decorator defining an option for a user name.
-
password_option–A CLI command decorator defining an option for a password.
-
host_option–A CLI command decorator defining an option for the host to connect to.
-
port_option–A CLI command decorator defining an option for the port to connect to.
-
safe_option–A CLI command decorator defining a flag for safe or unsafe connections.
-
identifier_option–A CLI command decorator defining an option for the YDoc identifier.
-
render_auto_save_option–A CLI command decorator defining an option for the renderers auto save feature.
-
render_timeout_option–A CLI command decorator defining an option for the renderers auto save timeout.
-
render_file_path_option–A CLI command decorator defining an option for the render file path.
-
render_options–A CLI command decorator defining render options.
-
data_file_path_argument–A CLI command decorator defining an argument for the data file path.
-
file_paths_option_and_argument–A CLI command decorator defining the render options and the data file path.
-
common_options–A CLI command decorator holding common CLI options.
PATH_TYPE = click.Path(path_type=Path, dir_okay=False, readable=False)
module-attribute
Default type of path parameters in the CLI API.
LEVEL = [None, logging.CRITICAL, logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG]
module-attribute
Logging level sorted by verbosity.
pass_config = pass_config_for()
module-attribute
configs_option = click.option('--config', '-c', 'configs', help='Path to config file. Overwrites default config file paths. Can be specified multiple times.', multiple=True, default=find_default_config_paths, type=PATH_TYPE)
module-attribute
A CLI command decorator defining an option for exclusive config file paths.
additional_configs_option = click.option('--additional-config', '-a', 'additional_configs', help='Path to config file in addition to the default paths. Can be specified multiple times.', multiple=True, type=PATH_TYPE)
module-attribute
A CLI command decorator defining an option for additional config file paths.
verbosity_option = click.option('--verbose', '-v', 'verbose', help='Verbosity of logging output.', count=True, type=(click.IntRange(0, 5, clamp=True)), callback=resolve_verbosity)
module-attribute
A CLI command decorator defining an option for log verbosity.
log_file_path_option = click.option('--log', '-l', 'log', help='Path to logging file.', type=PATH_TYPE)
module-attribute
A CLI command decorator defining an option for log file path.
display_name_option = click.option('--name', '-n', 'name', help='User display username.')
module-attribute
A CLI command decorator defining an option for the display name.
user_name_option = click.option('--user', '-u', 'user', help='Username for authentication.')
module-attribute
A CLI command decorator defining an option for a user name.
password_option = click.password_option('--password', 'password', help='Password for authentication', metavar='[TEXT]', prompt_required=False, type=(PasswordParameter()))
module-attribute
A CLI command decorator defining an option for a password.
host_option = click.option('--host', '-h', 'host', metavar='ADDRESS', help='Host of the syncing server.')
module-attribute
A CLI command decorator defining an option for the host to connect to.
port_option = click.option('--port', '-p', 'port', type=(click.INT), help='Port of the syncing server.')
module-attribute
A CLI command decorator defining an option for the port to connect to.
safe_option = click.option('--safe/--unsafe', 'safe', help='Enable or disable secure connection.', default=True)
module-attribute
A CLI command decorator defining a flag for safe or unsafe connections.
identifier_option = click.option('--identifier', '-i', 'identifier', help='Unique identifier of the shared document.', default=(str(uuid.uuid4())))
module-attribute
A CLI command decorator defining an option for the YDoc identifier.
render_auto_save_option = click.option('--auto-save/--no-auto-save', 'auto_save', is_flag=True, default=True, help='Enable automatic rendering of the file contents.')
module-attribute
A CLI command decorator defining an option for the renderers auto save feature.
render_timeout_option = click.option('--timeout', 'timeout', help='The time interval in seconds between consecutive renderings.', type=(click.IntRange(min=0)))
module-attribute
A CLI command decorator defining an option for the renderers auto save timeout.
render_file_path_option = click.option('--render', '-r', 'render', help='Path to rendered file.', required=False, type=PATH_TYPE)
module-attribute
A CLI command decorator defining an option for the render file path.
render_options = get_composed_decorator(render_file_path_option, render_auto_save_option, render_timeout_option)
module-attribute
A CLI command decorator defining render options.
data_file_path_argument = click.argument('file', required=False, type=PATH_TYPE, callback=resolve_data_file_path)
module-attribute
A CLI command decorator defining an argument for the data file path.
file_paths_option_and_argument = get_composed_decorator(render_options, data_file_path_argument)
module-attribute
A CLI command decorator defining the render options and the data file path.
common_options = get_composed_decorator(configs_option, additional_configs_option, identifier_option, display_name_option, user_name_option, password_option, host_option, port_option, safe_option, verbosity_option, log_file_path_option)
module-attribute
A CLI command decorator holding common CLI options.
warn(message)
get_composed_decorator(*decorators)
Compose a decorator out of many.
Given keyword arguments are used to include or exclude decorators by name.
Parameters:
-
decorators(Callable, default:()) –mapping of the decorator functions to their names.
Returns:
-
Callable–a decorator applying all given decorators.
Source code in src/elva/cli.py
get_data_file_path(path)
Ensure a correct and resolved data file path.
Parameters:
-
path(Path) –the path to the data file.
Returns:
-
Path–the correct and resolved data file path.
Source code in src/elva/cli.py
derive_stem(path, extension=None)
Derive the data file stem.
Parameters:
-
path(Path) –the path to the data file.
-
extension(None | str, default:None) –the extension to add to the stem.
Returns:
-
Path–the data file stem.
Source code in src/elva/cli.py
get_render_file_path(path)
get_log_file_path(path)
read_data_file(path)
Get metadata from file as parameter mapping.
Parameters:
Returns:
-
dict–parameter mapping stored in the ELVA SQLite database.
Source code in src/elva/cli.py
read_config_files(paths)
Get parameters defined in configuration files.
Parameters:
Returns:
-
list[Path]–parameter mapping from all configuration files.
-
dict–The value from the highest priority configuration overwrites all other parameter values.
Source code in src/elva/cli.py
merge_configs(ctx, app=None)
Update the user-defined parameters with parameters from files.
Order of Precedence (from highest to lowest)
- CLI, explicitely given values
- data file metadata
- additional config files, first has highest precedence
- project config files, nearest has highest precedence
- app directory config file
- CLI defaults
Parameters:
-
ctx(Context) –object holding the parameter mapping to be updated.
-
app(None | str, default:None) –parameters from the same named table in the configuration files.
Returns:
-
dict–a merged and cleaned mapping of configuration parameters to their values.
Source code in src/elva/cli.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | |
find_default_config_paths()
CLI default callback finding config files from highest to lowest precedence.
It first searches project files in the current working directory and in its parents, then in the OS-specific app directory.
Returns:
Source code in src/elva/cli.py
resolve_verbosity(ctx, param, value)
CLI callback converting counts of verbosity flags to log level names.
Parameters:
-
ctx(Context) –the context of the current command invokation.
-
param(Parameter) –the verbosity CLI parameter object.
-
value(None | int) –the value of the verbosity CLI parameter.
Returns:
-
None | str–the level name if the verbosity flag was given else
None.
Source code in src/elva/cli.py
resolve_data_file_path(ctx, param, path)
CLI callback ensuring a correct and resolved data file path.
Parameters:
-
ctx(Context) –the context of the current command invokation.
-
param(Parameter) –the data file CLI parameter object.
-
path(Path) –the value of the data file CLI parameter.
Returns:
-
None | Path–the correct and resolved data file path if given else
None.
Source code in src/elva/cli.py
pass_config_for(app=None)
Configure the pass_config decorator to respect the app table in configurations.
Parameters:
-
app(None | str, default:None) –the name of the app table to take configuration parameters from.
Raises:
-
ValueError–if
appis callable.
Returns:
-
Callable–the
pass_configdecorator configured forapp.