clan-config: add option --quiet
This commit is contained in:
@@ -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,6 +172,7 @@ 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)
|
||||||
|
if not quiet:
|
||||||
new_value = read_option(option)
|
new_value = read_option(option)
|
||||||
print(f"New Value for {option}:")
|
print(f"New Value for {option}:")
|
||||||
print(new_value)
|
print(new_value)
|
||||||
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user