From fedb542bbb0c7225ade10ab1e9de2c0a15826285 Mon Sep 17 00:00:00 2001 From: Damien Goutte-Gattat Date: Fri, 23 Aug 2024 13:43:34 +0100 Subject: [PATCH 1/3] Do not error out when seed is calling without a positional argument. Calling `odk.py seed` without any argument results in a crash because the `repo` variable (supposed to hold the name of the repository) is set to None, which is not expected by the Jinja template (it expects a string). When no positional arguments are specified, we set the `repo` variable to `noname` instead, thereby allowing the creation of a full repository with a dummy name instead of causing an error. --- odk/odk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/odk/odk.py b/odk/odk.py index 84d832d6..bd5a64e7 100755 --- a/odk/odk.py +++ b/odk/odk.py @@ -996,7 +996,7 @@ def seed(config, clean, outdir, templatedir, dependencies, title, user, source, raise Exception('max one repo; current={}'.format(repo)) repo = repo[0] else: - repo = None + repo = "noname" mg.load_config(config, imports=dependencies, title=title, From 2b059c4a29516d4cd13ad1ce33390eccf8a02f0c Mon Sep 17 00:00:00 2001 From: Damien Goutte-Gattat Date: Fri, 23 Aug 2024 13:46:22 +0100 Subject: [PATCH 2/3] Fail early if we don't have a Git username and email. When seeding, and unless the --skipgit option has been used, we need a username and email address to pass to Git. If we don't have those, the seeding process will crash at the very end, after all files have been generated. Since the Git username and email are necessary, we should detect whether we have them at the very beginning, and exit cleanly (with a message telling the user what they need to to) as soon as possible, without even initiating a process that is bound to fail. --- odk/odk.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/odk/odk.py b/odk/odk.py index bd5a64e7..df63357f 100755 --- a/odk/odk.py +++ b/odk/odk.py @@ -1007,6 +1007,11 @@ def seed(config, clean, outdir, templatedir, dependencies, title, user, source, project.id = repo if outdir is None: outdir = "target/{}".format(project.id) + if not skipgit: + if not "GIT_AUTHOR_NAME" in os.environ and not gitname: + raise click.ClickException("missing Git username; set GIT_AUTHOR_NAME or use --gitname") + if not "GIT_AUTHOR_EMAIL" in os.environ and not gitemail: + raise click.ClickException("missing Git email; set GIT_AUTHOR_EMAIL or use --gitemail") if clean: if os.path.exists(outdir): shutil.rmtree(outdir) From d38aa2dd5fbd556d459bdc723f0fa4851e4e9bcd Mon Sep 17 00:00:00 2001 From: Damien Goutte-Gattat Date: Fri, 23 Aug 2024 13:49:04 +0100 Subject: [PATCH 3/3] Do not show a stacktrace if we fail because we got too many args. The seed command expects only one positional arguments. If we got more than one, we should exit with a clean error message, instead of crashing with an uncaught exception and the associated stacktrace. --- odk/odk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/odk/odk.py b/odk/odk.py index df63357f..406a2ba2 100755 --- a/odk/odk.py +++ b/odk/odk.py @@ -993,7 +993,7 @@ def seed(config, clean, outdir, templatedir, dependencies, title, user, source, mg = Generator() if len(repo) > 0: if len(repo) > 1: - raise Exception('max one repo; current={}'.format(repo)) + raise click.ClickException('max one repo; current={}'.format(repo)) repo = repo[0] else: repo = "noname"