Skip to content

Commit 8c21b96

Browse files
authored
Merge pull request #1123 from yuvipanda/commandline-args
Allow passing in traitlets via commandline
2 parents b8a2c88 + 710d533 commit 8c21b96

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

repo2docker/__main__.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ def get_argparser():
6666
description="Fetch a repository and build a container image"
6767
)
6868

69+
argparser.add_argument(
70+
"--help-all",
71+
dest="help_all",
72+
action="store_true",
73+
help="Display all configurable options and exit.",
74+
)
75+
76+
argparser.add_argument(
77+
"--version",
78+
dest="version",
79+
action="store_true",
80+
help="Print the repo2docker version and exit.",
81+
)
82+
6983
argparser.add_argument(
7084
"--config",
7185
default="repo2docker_config.py",
@@ -222,13 +236,6 @@ def get_argparser():
222236

223237
argparser.add_argument("--subdir", type=str, help=Repo2Docker.subdir.help)
224238

225-
argparser.add_argument(
226-
"--version",
227-
dest="version",
228-
action="store_true",
229-
help="Print the repo2docker version and exit.",
230-
)
231-
232239
argparser.add_argument(
233240
"--cache-from", action="append", default=[], help=Repo2Docker.cache_from.help
234241
)
@@ -245,15 +252,24 @@ def make_r2d(argv=None):
245252
if argv is None:
246253
argv = sys.argv[1:]
247254

255+
argparser = get_argparser()
256+
248257
# version must be checked before parse, as repo/cmd are required and
249258
# will spit out an error if allowed to be parsed first.
250259
if "--version" in argv:
251260
print(__version__)
252261
sys.exit(0)
253262

254-
args = get_argparser().parse_args(argv)
263+
if "--help-all" in argv:
264+
argparser.print_help()
265+
print("\nAll configurable options:\n")
266+
Repo2Docker().print_help(classes=True)
267+
sys.exit(0)
268+
269+
args, traitlet_args = argparser.parse_known_args(argv)
255270

256271
r2d = Repo2Docker()
272+
r2d.parse_command_line(traitlet_args)
257273

258274
if args.debug:
259275
r2d.log_level = logging.DEBUG

repo2docker/app.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ class Repo2Docker(Application):
4747
name = "jupyter-repo2docker"
4848
version = __version__
4949
description = __doc__
50+
# disable aliases/flags because we don't use the traitlets for CLI parsing
51+
# other than --Class.trait=value
52+
aliases = {}
53+
flags = {}
5054

5155
@default("log_level")
5256
def _default_log_level(self):
@@ -490,7 +494,7 @@ def json_excepthook(self, etype, evalue, traceback):
490494
extra=dict(phase="failed"),
491495
)
492496

493-
def initialize(self):
497+
def initialize(self, *args, **kwargs):
494498
"""Init repo2docker configuration before start"""
495499
# FIXME: Remove this function, move it to setters / traitlet reactors
496500
if self.json_logs:

0 commit comments

Comments
 (0)