edq .cli .config .list
List the current configuration options.
usage: python3 -m edq.cli.config.list [-h] [--show-origin] [--skip-header]
List the current configuration options.
options:
-h, --help show this help message and exit
list options:
--show-origin Display where each configuration's value was obtained from.
--skip-header Skip headers when displaying configs.
1""" 2List the current configuration options. 3""" 4 5import argparse 6import sys 7 8import edq.core.argparser 9 10CONFIG_FIELD_SEPARATOR: str = "\t" 11 12def run_cli(args: argparse.Namespace) -> int: 13 """ Run the CLI. """ 14 15 config_info = args._config_info 16 17 rows = [] 18 for (key, value) in config_info.config.items(): 19 row = [key, str(value)] 20 if (args.show_origin): 21 config_source_obj = config_info.sources.get(key) 22 23 origin = config_source_obj.path 24 if (origin is None): 25 origin = config_source_obj.label 26 27 row.append(origin) 28 29 rows.append(CONFIG_FIELD_SEPARATOR.join(row)) 30 31 rows.sort() 32 33 if (not args.skip_header): 34 header = ["Key", "Value"] 35 if (args.show_origin): 36 header.append("Origin") 37 38 rows.insert(0, (CONFIG_FIELD_SEPARATOR.join(header))) 39 40 print("\n".join(rows)) 41 return 0 42 43def main() -> int: 44 """ Get a parser, parse the args, and call run. """ 45 46 return run_cli(_get_parser().parse_args()) 47 48def _get_parser() -> argparse.ArgumentParser: 49 """ Get a parser and add addition flags. """ 50 51 parser = edq.core.argparser.get_default_parser(__doc__.strip()) 52 modify_parser(parser) 53 54 return parser 55 56def modify_parser(parser: argparse.ArgumentParser) -> None: 57 """ Add this CLI's flags to the given parser. """ 58 59 group = parser.add_argument_group('list options') 60 61 group.add_argument("--show-origin", dest = 'show_origin', 62 action = 'store_true', 63 help = "Display where each configuration's value was obtained from.", 64 ) 65 66 group.add_argument("--skip-header", dest = 'skip_header', 67 action = 'store_true', 68 help = 'Skip headers when displaying configs.', 69 ) 70 71if (__name__ == '__main__'): 72 sys.exit(main())
CONFIG_FIELD_SEPARATOR: str =
'\t'
def
run_cli(args: argparse.Namespace) -> int:
13def run_cli(args: argparse.Namespace) -> int: 14 """ Run the CLI. """ 15 16 config_info = args._config_info 17 18 rows = [] 19 for (key, value) in config_info.config.items(): 20 row = [key, str(value)] 21 if (args.show_origin): 22 config_source_obj = config_info.sources.get(key) 23 24 origin = config_source_obj.path 25 if (origin is None): 26 origin = config_source_obj.label 27 28 row.append(origin) 29 30 rows.append(CONFIG_FIELD_SEPARATOR.join(row)) 31 32 rows.sort() 33 34 if (not args.skip_header): 35 header = ["Key", "Value"] 36 if (args.show_origin): 37 header.append("Origin") 38 39 rows.insert(0, (CONFIG_FIELD_SEPARATOR.join(header))) 40 41 print("\n".join(rows)) 42 return 0
Run the CLI.
def
main() -> int:
44def main() -> int: 45 """ Get a parser, parse the args, and call run. """ 46 47 return run_cli(_get_parser().parse_args())
Get a parser, parse the args, and call run.
def
modify_parser(parser: argparse.ArgumentParser) -> None:
57def modify_parser(parser: argparse.ArgumentParser) -> None: 58 """ Add this CLI's flags to the given parser. """ 59 60 group = parser.add_argument_group('list options') 61 62 group.add_argument("--show-origin", dest = 'show_origin', 63 action = 'store_true', 64 help = "Display where each configuration's value was obtained from.", 65 ) 66 67 group.add_argument("--skip-header", dest = 'skip_header', 68 action = 'store_true', 69 help = 'Skip headers when displaying configs.', 70 )
Add this CLI's flags to the given parser.