Skip to content

Commit

Permalink
combine: use argparse required=True for --target
Browse files Browse the repository at this point in the history
  • Loading branch information
lowell80 committed Oct 3, 2023
1 parent 6f95d9f commit f25aa7f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/source/dyn/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ ksconf combine

.. code-block:: none
usage: ksconf combine [-h] [--target TARGET] [-m {auto,dir.d,disable}] [-q]
usage: ksconf combine [-h] --target TARGET [-m {auto,dir.d,disable}] [-q]
[-I PATTERN] [-E PATTERN] [--enable-handler {jinja}]
[--template-vars TEMPLATE_VARS] [--dry-run]
[--follow-symlink] [--banner BANNER] [-K KEEP_EXISTING]
Expand Down
8 changes: 2 additions & 6 deletions ksconf/commands/combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from ksconf.commands import KsconfCmd, add_file_handler, dedent
from ksconf.compat import List
from ksconf.consts import (EXIT_CODE_BAD_ARGS, EXIT_CODE_COMBINE_MARKER_MISSING,
EXIT_CODE_MISSING_ARG, EXIT_CODE_NO_SUCH_FILE)
EXIT_CODE_NO_SUCH_FILE)
from ksconf.filter import create_filtered_list
from ksconf.layer import LayerFile, layer_file_factory
from ksconf.util.completers import DirectoriesCompleter
Expand Down Expand Up @@ -172,7 +172,7 @@ def f(pattern):
with the specific; later sources will override values from the earlier ones.
Supports wildcards so a typical Unix ``conf.d/##-NAME`` directory structure works well.""")
).completer = DirectoriesCompleter()
parser.add_argument("--target", "-t", help=dedent("""
parser.add_argument("--target", "-t", required=True, help=dedent("""
Directory where the merged files will be stored.
Typically either 'default' or 'local'""")
).completer = DirectoriesCompleter()
Expand Down Expand Up @@ -278,10 +278,6 @@ def run(self, args):
self.stderr.write(f"Reading conf files from directory {src}\n")
combiner.set_source_dirs(args.source)

if args.target is None:
self.stderr.write("Must provide the '--target' directory.\n")
return EXIT_CODE_MISSING_ARG

self.stderr.write(f"Combining files into directory {args.target}\n")

try:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli_combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def test_combine_conf_spec(self):
def test_require_arg(self):
with ksconf_cli:
ko = ksconf_cli("combine", "source-dir")
self.assertRegex(ko.stderr, "Must provide [^\r\n]+--target")
self.assertRegex(ko.stderr, "arguments are required: --target")

def test_missing_marker(self):
twd = TestWorkDir()
Expand Down

0 comments on commit f25aa7f

Please sign in to comment.