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