Skip to content

Commit 98724fb

Browse files
committed
handle more options from config
- warn if repo is specified in config, because it doesn't make sense and will be ignored - only override config for ref/image/run/build if specified on the cli requires both-directions config for run and build, to handle the default being inverted in a config file
1 parent b841dea commit 98724fb

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

repo2docker/__main__.py

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def get_argparser():
114114

115115
argparser.add_argument(
116116
"--ref",
117+
default=None,
117118
help=(
118119
"Reference to build instead of default reference. For example"
119120
" branch name or commit for a Git repository."
@@ -129,6 +130,14 @@ def get_argparser():
129130
help="Do not actually build the image. Useful in conjunction with --debug.",
130131
)
131132

133+
argparser.add_argument(
134+
"--build",
135+
dest="build",
136+
action="store_true",
137+
help="Build the image (default)",
138+
)
139+
argparser.set_defaults(build=None)
140+
132141
argparser.add_argument(
133142
"--build-memory-limit",
134143
help="Total Memory that can be used by the docker build process",
@@ -147,6 +156,14 @@ def get_argparser():
147156
help="Do not run container after it has been built",
148157
)
149158

159+
argparser.add_argument(
160+
"--run",
161+
dest="run",
162+
action="store_true",
163+
help="Run container after it has been built (default).",
164+
)
165+
argparser.set_defaults(run=None)
166+
150167
argparser.add_argument(
151168
"--publish",
152169
"-p",
@@ -181,6 +198,13 @@ def get_argparser():
181198
action="store_true",
182199
help="Push docker image to repository",
183200
)
201+
argparser.add_argument(
202+
"--no-push",
203+
dest="push",
204+
action="store_false",
205+
help="Don't push docker image to repository (default).",
206+
)
207+
argparser.set_defaults(push=None)
184208

185209
argparser.add_argument(
186210
"--volume",
@@ -298,8 +322,14 @@ def make_r2d(argv=None):
298322
key, _, val = a.partition("=")
299323
r2d.extra_build_args[key] = val
300324

325+
# repo is a required arg, and should never come from config:
326+
if "repo" in r2d.config.Repo2Docker:
327+
r2d.log.warning(
328+
f"Ignoring Repo2Docker.repo={r2d.repo!r} configuration, using {args.repo!r} from CLI."
329+
)
301330
r2d.repo = args.repo
302-
r2d.ref = args.ref
331+
if args.ref is not None:
332+
r2d.ref = args.ref
303333

304334
# user wants to mount a local directory into the container for
305335
# editing
@@ -320,22 +350,22 @@ def make_r2d(argv=None):
320350

321351
if args.image_name:
322352
r2d.output_image_spec = args.image_name
323-
else:
324-
# we will pick a name after fetching the repository
325-
r2d.output_image_spec = ""
326353

327354
if args.json_logs is not None:
328355
r2d.json_logs = args.json_logs
329356

330-
r2d.dry_run = not args.build
357+
if args.build is not None:
358+
r2d.dry_run = not args.build
331359

332360
if r2d.dry_run:
333361
# Can't push nor run if we aren't building
334362
args.run = False
335363
args.push = False
336364

337-
r2d.run = args.run
338-
r2d.push = args.push
365+
if args.run is not None:
366+
r2d.run = args.run
367+
if args.push is not None:
368+
r2d.push = args.push
339369

340370
# check against r2d.run and not args.run as r2d.run is false on
341371
# --no-build. Also r2d.volumes and not args.volumes since --editable

0 commit comments

Comments
 (0)