cli.py

mdpo command line interface utilities.

mdpo.cli.add_common_cli_first_arguments(parser, quiet=True)

Add common mdpo arguments to an argument parser at the beginning.

Parameters
mdpo.cli.add_common_cli_latest_arguments(parser)

Add common mdpo arguments to an argument parser at the end.

Parameters

parser (argparse.ArgumentParser) – Arguments parser to extend.

mdpo.cli.add_debug_option(parser)

Add the -D/--debug option to an argument parser.

Parameters

parser (argparse.ArgumentParser) – Arguments parser to extend.

mdpo.cli.add_encoding_arguments(parser, po_encoding_help=None)

Add --po-encoding --md_encoding arguments to an argument parser.

Parameters
  • parser (argparse.ArgumentParser) – Arguments parser to extend.

  • po_encoding_help (str) – Help text for the --po-encoding argument.

mdpo.cli.add_extensions_argument(parser)

Add the -x/--extension argument to an argument parser.

Parameters

parser (argparse.ArgumentParser) – Arguments parser to extend.

mdpo.cli.add_nolocation_option(parser)

Add the --no-location/--nolocation option to an argument parser.

Parameters

parser (argparse.ArgumentParser) – Arguments parser to extend.

mdpo.cli.add_pre_commit_option(parser)

Add the --pre-commit option to an argument parser.

Parameters

parser (argparse.ArgumentParser) – Arguments parser to extend.

mdpo.cli.parse_command_aliases_cli_arguments(command_aliases)

Parse --command-alias argument values passed to CLIs.

If a value can’t be passed or a custom command is duplicated, writes an appropiate error message to STDERR and exits with code 1.

Parameters

command_aliases (list) – Values taken by --command-alias arguments.

Returns

Command aliases mapping ni the format accepted by the API.

Return type

dict

mdpo.cli.parse_escaped_pairs_cli_argument(pairs, value_error_message, key_error_message)

Parses a key argument made by key-value pairs.

If an error happens, shows an appropiate message and exists with code 1.

Parameters
  • pairs (list) – List of key-value pairs.

  • value_error_message (str) – Error message schema shown when a pair can’t be parsed.

  • key_error_message (str) – Error message schema shown when a key is repeated.

Returns

Parsed key-value pairs.

Return type

dict

mdpo.cli.parse_metadata_cli_arguments(metadata)

Parse --metadata argument values passed to CLIs.

If a value can’t be passed or a metadata key is duplicated, writes an appropiate error message to STDERR and exits with code 1.

Parameters

metadata (list) – Values taken by --metadata arguments.

Returns

Metadata mapping ni the format accepted by the API.

Return type

dict