edq .cli .config .set
Update configuration options.
The file at the specified config location will be created if it doesn't exist.
usage: python3 -m edq.cli.config.set [-h] [--local | --global | --file ]
= [= ...]
Update configuration options. The file at the specified config location will
be created if it doesn't exist.
positional arguments:
= Configuration option to be set. Expected config format is
=.
options:
-h, --help show this help message and exit
config location options:
--local Target config option(s) in a local config file.
--global Target config option(s) in the global config file.
--file Target config option(s) in a specified config file.
1""" 2Update configuration options. 3 4The file at the specified config location will be created if it doesn't exist. 5""" 6 7import argparse 8import os 9import sys 10import typing 11 12import edq.core.argparser 13import edq.core.config 14 15def run_cli(args: argparse.Namespace) -> int: 16 """ Run the CLI. """ 17 18 config_to_set: typing.Dict[str, str] = {} 19 for config_option in args.config_to_set: 20 (key, value) = edq.core.config.parse_string_config_option(config_option) 21 config_to_set[key] = value 22 23 out_path = edq.core.config.resolve_config_location( 24 args._config_info, 25 args.scope_local, 26 args.scope_global, 27 args.scope_file, 28 ) 29 30 edq.core.config.update_options_in_config_file(out_path, config_to_set) 31 print(f"Wrote config options to: '{os.path.abspath(out_path)}'.") 32 33 return 0 34 35def main() -> int: 36 """ Get a parser, parse the args, and call run. """ 37 38 return run_cli(_get_parser().parse_args()) 39 40def _get_parser() -> argparse.ArgumentParser: 41 """ Get a parser and add additional flags. """ 42 43 parser = edq.core.argparser.get_default_parser(__doc__.strip()) 44 modify_parser(parser) 45 46 return parser 47 48def modify_parser(parser: argparse.ArgumentParser) -> None: 49 """ Add this CLI's flags to the given parser. """ 50 51 parser.add_argument('config_to_set', metavar = "<KEY>=<VALUE>", 52 action = 'store', nargs = '+', type = str, 53 help = ("Configuration option to be set." 54 + " Expected config format is <key>=<value>."), 55 ) 56 57 edq.core.config.add_config_location_argument_group(parser) 58 59if (__name__ == '__main__'): 60 sys.exit(main())
def
run_cli(args: argparse.Namespace) -> int:
16def run_cli(args: argparse.Namespace) -> int: 17 """ Run the CLI. """ 18 19 config_to_set: typing.Dict[str, str] = {} 20 for config_option in args.config_to_set: 21 (key, value) = edq.core.config.parse_string_config_option(config_option) 22 config_to_set[key] = value 23 24 out_path = edq.core.config.resolve_config_location( 25 args._config_info, 26 args.scope_local, 27 args.scope_global, 28 args.scope_file, 29 ) 30 31 edq.core.config.update_options_in_config_file(out_path, config_to_set) 32 print(f"Wrote config options to: '{os.path.abspath(out_path)}'.") 33 34 return 0
Run the CLI.
def
main() -> int:
36def main() -> int: 37 """ Get a parser, parse the args, and call run. """ 38 39 return run_cli(_get_parser().parse_args())
Get a parser, parse the args, and call run.
def
modify_parser(parser: argparse.ArgumentParser) -> None:
49def modify_parser(parser: argparse.ArgumentParser) -> None: 50 """ Add this CLI's flags to the given parser. """ 51 52 parser.add_argument('config_to_set', metavar = "<KEY>=<VALUE>", 53 action = 'store', nargs = '+', type = str, 54 help = ("Configuration option to be set." 55 + " Expected config format is <key>=<value>."), 56 ) 57 58 edq.core.config.add_config_location_argument_group(parser)
Add this CLI's flags to the given parser.