clan-config: add option --quiet
All checks were successful
build / test (pull_request) Successful in 25s
All checks were successful
build / test (pull_request) Successful in 25s
This commit is contained in:
parent
999fbe0d89
commit
b16f314c80
@ -124,6 +124,7 @@ def process_args(
|
|||||||
value: Any,
|
value: Any,
|
||||||
options: dict,
|
options: dict,
|
||||||
settings_file: Path,
|
settings_file: Path,
|
||||||
|
quiet: bool = False,
|
||||||
option_description: str = "",
|
option_description: str = "",
|
||||||
) -> None:
|
) -> None:
|
||||||
if value == []:
|
if value == []:
|
||||||
@ -144,6 +145,7 @@ def process_args(
|
|||||||
value={attr: value},
|
value={attr: value},
|
||||||
options=options,
|
options=options,
|
||||||
settings_file=settings_file,
|
settings_file=settings_file,
|
||||||
|
quiet=quiet,
|
||||||
option_description=option,
|
option_description=option,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -170,9 +172,10 @@ def process_args(
|
|||||||
new_config = merge(current_config, result)
|
new_config = merge(current_config, result)
|
||||||
with open(settings_file, "w") as f:
|
with open(settings_file, "w") as f:
|
||||||
json.dump(new_config, f, indent=2)
|
json.dump(new_config, f, indent=2)
|
||||||
new_value = read_option(option)
|
if not quiet:
|
||||||
print(f"New Value for {option}:")
|
new_value = read_option(option)
|
||||||
print(new_value)
|
print(f"New Value for {option}:")
|
||||||
|
print(new_value)
|
||||||
|
|
||||||
|
|
||||||
def register_parser(
|
def register_parser(
|
||||||
@ -218,10 +221,19 @@ def _register_parser(
|
|||||||
option=args.option,
|
option=args.option,
|
||||||
value=args.value,
|
value=args.value,
|
||||||
options=options,
|
options=options,
|
||||||
|
quiet=args.quiet,
|
||||||
settings_file=args.settings_file,
|
settings_file=args.settings_file,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# add --quiet option
|
||||||
|
parser.add_argument(
|
||||||
|
"--quiet",
|
||||||
|
"-q",
|
||||||
|
help="Suppress output",
|
||||||
|
action="store_true",
|
||||||
|
)
|
||||||
|
|
||||||
# add argument to pass output file
|
# add argument to pass output file
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--settings-file",
|
"--settings-file",
|
||||||
|
@ -29,7 +29,6 @@ example_options = f"{Path(config.__file__).parent}/jsonschema/options.json"
|
|||||||
def test_set_some_option(
|
def test_set_some_option(
|
||||||
argv: list[str],
|
argv: list[str],
|
||||||
expected: dict[str, Any],
|
expected: dict[str, Any],
|
||||||
capsys: pytest.CaptureFixture,
|
|
||||||
monkeypatch: pytest.MonkeyPatch,
|
monkeypatch: pytest.MonkeyPatch,
|
||||||
) -> None:
|
) -> None:
|
||||||
# monkeypatch sys.argv
|
# monkeypatch sys.argv
|
||||||
@ -37,7 +36,9 @@ def test_set_some_option(
|
|||||||
with tempfile.NamedTemporaryFile() as out_file:
|
with tempfile.NamedTemporaryFile() as out_file:
|
||||||
with open(out_file.name, "w") as f:
|
with open(out_file.name, "w") as f:
|
||||||
json.dump({}, f)
|
json.dump({}, f)
|
||||||
monkeypatch.setattr(sys, "argv", ["", "--settings-file", out_file.name] + argv)
|
monkeypatch.setattr(
|
||||||
|
sys, "argv", ["", "--quiet", "--settings-file", out_file.name] + argv
|
||||||
|
)
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
config._register_parser(
|
config._register_parser(
|
||||||
parser=parser,
|
parser=parser,
|
||||||
|
Loading…
Reference in New Issue
Block a user