edq .cli .config .unset
Unset configuration options.
Does nothing if the file at the specified config location doesn't exist.
usage: python3 -m edq.cli.config.unset [-h]
[--local | --global | --file ]
KEY [KEY ...]
Unset configuration options. Does nothing if the file at the specified config
location doesn't exist.
positional arguments:
KEY Configuration key to unset.
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""" 2Unset configuration options. 3 4Does nothing if the file at the specified config location doesn't exist. 5""" 6 7import argparse 8import os 9import sys 10 11import edq.core.argparser 12import edq.core.config 13 14def run_cli(args: argparse.Namespace) -> int: 15 """ Run the CLI. """ 16 17 out_path = edq.core.config.resolve_config_location( 18 args._config_info, 19 args.scope_local, 20 args.scope_global, 21 args.scope_file, 22 ) 23 24 if (not (edq.util.dirent.exists(out_path))): 25 print(f"Config file does not exist: '{os.path.abspath(out_path)}'.") 26 return 0 27 28 edq.core.config.remove_options_in_config_file(out_path, args.config_to_unset) 29 print(f"Unset config options from: '{os.path.abspath(out_path)}'.") 30 31 return 0 32 33def main() -> int: 34 """ Get a parser, parse the args, and call run. """ 35 36 return run_cli(_get_parser().parse_args()) 37 38def _get_parser() -> argparse.ArgumentParser: 39 """ Get a parser and add additional flags. """ 40 41 parser = edq.core.argparser.get_default_parser(__doc__.strip()) 42 modify_parser(parser) 43 44 return parser 45 46def modify_parser(parser: argparse.ArgumentParser) -> None: 47 """ Add this CLI's flags to the given parser. """ 48 49 parser.add_argument('config_to_unset', metavar = "KEY", 50 action = 'store', nargs = '+', type = str, 51 help = ("Configuration key to unset."), 52 ) 53 54 edq.core.config.add_config_location_argument_group(parser) 55 56if (__name__ == '__main__'): 57 sys.exit(main())
def
run_cli(args: argparse.Namespace) -> int:
15def run_cli(args: argparse.Namespace) -> int: 16 """ Run the CLI. """ 17 18 out_path = edq.core.config.resolve_config_location( 19 args._config_info, 20 args.scope_local, 21 args.scope_global, 22 args.scope_file, 23 ) 24 25 if (not (edq.util.dirent.exists(out_path))): 26 print(f"Config file does not exist: '{os.path.abspath(out_path)}'.") 27 return 0 28 29 edq.core.config.remove_options_in_config_file(out_path, args.config_to_unset) 30 print(f"Unset config options from: '{os.path.abspath(out_path)}'.") 31 32 return 0
Run the CLI.
def
main() -> int:
34def main() -> int: 35 """ Get a parser, parse the args, and call run. """ 36 37 return run_cli(_get_parser().parse_args())
Get a parser, parse the args, and call run.
def
modify_parser(parser: argparse.ArgumentParser) -> None:
47def modify_parser(parser: argparse.ArgumentParser) -> None: 48 """ Add this CLI's flags to the given parser. """ 49 50 parser.add_argument('config_to_unset', metavar = "KEY", 51 action = 'store', nargs = '+', type = str, 52 help = ("Configuration key to unset."), 53 ) 54 55 edq.core.config.add_config_location_argument_group(parser)
Add this CLI's flags to the given parser.