Skip to content

Commit 1078d04

Browse files
authored
Merge pull request #180 from minrk/reset-exclusive
Enforce that `--reset` is an exclusive argument
2 parents ab9e7e1 + ee370e8 commit 1078d04

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

chartpress.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import os
99
import pipes
1010
import re
11+
import shlex
1112
import shutil
1213
import subprocess
1314
import sys
@@ -1038,7 +1039,7 @@ def __call__(self, parser, namespace, values, option_string=None):
10381039
getattr(namespace, self.dest).append(values)
10391040

10401041

1041-
def main(args=None):
1042+
def main(argv=None):
10421043
"""Run chartpress"""
10431044
argparser = argparse.ArgumentParser(description=__doc__)
10441045

@@ -1127,24 +1128,33 @@ def main(args=None):
11271128
)
11281129
argparser.add_argument(
11291130
"--version",
1130-
action="store_true",
1131-
help="Print current chartpress version and exit.",
1131+
action="version",
1132+
version=f"chartpress version {__version__}",
11321133
)
11331134

1134-
args = argparser.parse_args(args)
1135+
args = argparser.parse_args(argv)
11351136
if args.builder == Builder.DOCKER_BUILD and args.platform:
11361137
argparser.error(f"--platform is not supported with {Builder.DOCKER_BUILD}")
11371138

1139+
if args.reset:
1140+
# reset conflicts with everything
1141+
# this could probably be clearer by using subparsers
1142+
argv = list(argv or sys.argv[1:])
1143+
if len(argv) > 1:
1144+
argv = list(argv)
1145+
argv.remove("--reset")
1146+
extra_args = " ".join(shlex.quote(arg) for arg in argv if arg != "--reset")
1147+
argparser.error(
1148+
f"`chartpress --reset` takes no additional arguments: {extra_args}"
1149+
)
1150+
11381151
# allow simple checks for whether publish will happen
11391152
if args.force_publish_chart:
11401153
args.publish_chart = True
11411154

1142-
if args.version:
1143-
print(f"chartpress version {__version__}")
1144-
return
1145-
1146-
if args.list_images:
1155+
if args.list_images or args.reset:
11471156
args.no_build = True
1157+
args.publish_chart = False
11481158

11491159
with open("chartpress.yaml") as f:
11501160
config = yaml.load(f)

tests/test_repo_interactions.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ def test_chartpress_run(git_repo, capfd, base_version):
7575
f"Updating testchart/values.yaml: image: testchart/testimage:{reset_tag}" in out
7676
)
7777

78-
# --tag overrides resetVersion config
79-
out = _capture_output(["--reset", "--tag=1.0.0-dev"], capfd)
80-
assert "Updating testchart/Chart.yaml: version: 1.0.0-dev" in out
81-
assert "Updating testchart/values.yaml: image: testchart/testimage:1.0.0-dev" in out
82-
8378
# verify that we don't need to rebuild the image
8479
out = _capture_output([], capfd)
8580
assert "Skipping build" in out
@@ -406,3 +401,10 @@ def test_reset(git_repo, capfd):
406401
expected_tag = chart_cfg["resetTag"]
407402

408403
assert values["image"] == f"testchart/testimage:{expected_tag}"
404+
405+
406+
def test_reset_exclusive(git_repo, capfd):
407+
with pytest.raises(SystemExit):
408+
chartpress.main(["--reset", "--tag", "1.2.3"])
409+
out, err = capfd.readouterr()
410+
assert "no additional arguments" in err

0 commit comments

Comments
 (0)