From 7f2eb037c4f391db8a78fea6e2ff13179742ecb7 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Oct 09 2019 16:51:41 +0000 Subject: cli: Print a warning in latest-build if the tag is not a buildroot If you accidentally use latest-build with a tag argument that is not a buildroot, latest-build gives very confusing results. This mistake is easy to make if the tag builds into a buildroot of a different name. With this patch, we now a warning and suggest to use the corresponding buildroot tag instead: $ koji latest-build f32 glibc warning: 'f32' is not a buildroot tag warning: Did you mean 'f32-build' instead? Build Tag Built by ---------------------------------------- -------------------- ---------------- glibc-2.30.9000-11.fc32 f32 submachine --- diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index 513ee22..95fded7 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -2310,6 +2310,9 @@ def anon_handle_latest_build(goptions, session, args): help=_("Do not print the header information")) parser.add_option("--paths", action="store_true", help=_("Show the file paths")) parser.add_option("--type", help=_("Show builds of the given type only. Currently supported types: maven")) + parser.add_option("--disable-buildroot-check", action="store_true", + default=False, + help=_("Do not check that the tag has a buildroot")) (options, args) = parser.parse_args(args) if len(args) == 0: parser.error(_("A tag name must be specified")) @@ -2327,6 +2330,19 @@ def anon_handle_latest_build(goptions, session, args): assert False # pragma: no cover pathinfo = koji.PathInfo() + if not options.disable_buildroot_check: + targets = session.getBuildTargets(args[0]) + build_tag_names = [target["build_tag_name"] for target in targets] + if targets and args[0] not in build_tag_names: + warn(_("warning: %r is not a buildroot tag.") % args[0]) + if len(build_tag_names) == 1: + warn(_("warning: Did you mean %r instead?") + % build_tag_names[0]) + else: + warn(_("warning: Did you mean any of %s instead?") + % ", ".join([repr(suggestion) + for suggestion in build_tag_names])) + for pkg in args[1:]: if options.arch: rpms, builds = session.getLatestRPMS(args[0], package=pkg, arch=options.arch)