def parse_command_line( argv: List[str]) -> Tuple[Namespace, DarkerConfig, DarkerConfig]: """Return the parsed command line, using defaults from a configuration file Also return the effective configuration which combines defaults, the configuration read from ``pyproject.toml`` (or the path given in ``--config``), and command line arguments. Finally, also return the set of configuration options which differ from defaults. """ # 1. Parse the paths of files/directories to process into `args.src`. parser_for_srcs = make_argument_parser(require_src=False) args = parser_for_srcs.parse_args(argv) # 2. Locate `pyproject.toml` based on those paths, or in the current directory if no # paths were given. Load Darker configuration from it. config = load_config(args.src) # 3. Use configuration as defaults for re-parsing command line arguments, and don't # require file/directory paths if they are specified in configuration. parser = make_argument_parser(require_src=not config.get("src")) parser.set_defaults(**config) args = parser.parse_args(argv) # 4. Also create a parser which uses the original default configuration values. # This is used to find out differences between the effective configuration and # default configuration values, and print them out in verbose mode. parser_with_original_defaults = make_argument_parser(require_src=True) return ( args, get_effective_config(args), get_modified_config(parser_with_original_defaults, args), )
def test_get_modified_config(args, expect): parser = ArgumentParser() parser.add_argument("names", nargs="*", default=["foo"]) parser.add_argument("--int", dest="int", default=42) parser.add_argument("--string", default="fourty-two") result = get_modified_config(parser, args) assert result == expect