Skip to content

Commit

Permalink
minimize: warn user if '--target' is omitted
Browse files Browse the repository at this point in the history
- Added logic to check if TARGET has not been provided by the user and output a
  warning to the user.  This fixes #70.
- Added unit test to confirm that missing '--target' is properly reported.
  • Loading branch information
lowell80 committed Apr 24, 2020
1 parent 0336ae4 commit 75fafd8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ksconf/commands/minimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from ksconf.commands import KsconfCmd, dedent, ConfFileType
from ksconf.conf.delta import compare_cfgs, DIFF_OP_DELETE, DIFF_OP_EQUAL, DiffStanza, \
DIFF_OP_INSERT, DIFF_OP_REPLACE, show_diff
from ksconf.consts import EXIT_CODE_MISSING_ARG
from ksconf.conf.merge import merge_conf_dicts
from ksconf.conf.parser import GLOBAL_STANZA, _drop_stanza_comments
from ksconf.conf.parser import PARSECONF_STRICT, PARSECONF_LOOSE
Expand Down Expand Up @@ -84,6 +85,9 @@ def register_args(self, parser):
"Specify attributes that should always be kept.")

def run(self, args):
if not args.target:
self.stderr.write("You must specify the target file with '--target'.\n")
return EXIT_CODE_MISSING_ARG
if args.explode_default:
# Is this the SAME as exploding the defaults AFTER the merge?;
# I think NOT. Needs testing
Expand Down
11 changes: 11 additions & 0 deletions tests/test_cli_minimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ def test_minimize_explode_defaults(self):
self.assertTrue(orig_size > final_size)


def test_missing_target(self):
twd = TestWorkDir()
local = twd.copy_static("inputs-ta-nix-local.conf", "inputs.conf")
default = static_data("inputs-ta-nix-default.conf")
inputs_min = twd.get_path("inputs-new.conf")
rebuilt = twd.get_path("inputs-rebuild.conf")
with ksconf_cli:
ko = ksconf_cli("minimize", "--output", inputs_min, local, default)
self.assertEqual(ko.returncode, EXIT_CODE_MISSING_ARG)
self.assertIn("--target", ko.stderr)


if __name__ == '__main__': # pragma: no cover
unittest.main()

0 comments on commit 75fafd8

Please sign in to comment.