ArgumentParser instead of ArgumentParser in sidetag CLI plugin
Fixes: https://pagure.io/koji/issue/3739
This commit is contained in:
parent
3f3c56fd75
commit
2139b237d0
3 changed files with 62 additions and 59 deletions
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from argparse import ArgumentParser
|
||||
from optparse import OptionParser
|
||||
|
||||
import koji
|
||||
from koji.plugin import export_cli
|
||||
|
|
@ -16,18 +16,21 @@ from koji_cli.lib import activate_session, arg_filter
|
|||
@export_cli
|
||||
def handle_add_sidetag(options, session, args):
|
||||
"Create sidetag"
|
||||
usage = "%(prog)s add-sidetag [options] <basetag>"
|
||||
usage = "%prog add-sidetag [options] <basetag>"
|
||||
usage += "\n(Specify the --help global option for a list of other help options)"
|
||||
parser = ArgumentParser(usage=usage)
|
||||
parser.add_argument("basetag", help="name of basetag")
|
||||
parser.add_argument("-q", "--quiet", action="store_true", help="Do not print tag name",
|
||||
default=options.quiet)
|
||||
parser.add_argument("-w", "--wait", action="store_true", help="Wait until repo is ready.")
|
||||
parser.add_argument("--debuginfo", action="store_true",
|
||||
help="Buildroot repo will contain debuginfos")
|
||||
parser.add_argument("--suffix", action="store", help="Suffix from hub-supported ones")
|
||||
parser = OptionParser(usage=usage)
|
||||
parser.add_option("-q", "--quiet", action="store_true", help="Do not print tag name",
|
||||
default=options.quiet)
|
||||
parser.add_option("-w", "--wait", action="store_true", help="Wait until repo is ready.")
|
||||
parser.add_option("--debuginfo", action="store_true",
|
||||
help="Buildroot repo will contain debuginfos")
|
||||
parser.add_option("--suffix", action="store", help="Suffix from hub-supported ones")
|
||||
|
||||
opts = parser.parse_args(args)
|
||||
(opts, args) = parser.parse_args(args)
|
||||
|
||||
if len(args) != 1:
|
||||
parser.error("Only argument is basetag")
|
||||
basetag = args[0]
|
||||
|
||||
activate_session(session, options)
|
||||
|
||||
|
|
@ -35,7 +38,7 @@ def handle_add_sidetag(options, session, args):
|
|||
if opts.suffix:
|
||||
kwargs['suffix'] = opts.suffix
|
||||
try:
|
||||
tag = session.createSideTag(opts.basetag, **kwargs)
|
||||
tag = session.createSideTag(basetag, **kwargs)
|
||||
except koji.ActionNotAllowed:
|
||||
parser.error("Policy violation")
|
||||
except koji.ParameterError as ex:
|
||||
|
|
@ -57,16 +60,18 @@ def handle_add_sidetag(options, session, args):
|
|||
@export_cli
|
||||
def handle_remove_sidetag(options, session, args):
|
||||
"Remove sidetag"
|
||||
usage = "%(prog)s remove-sidetag [options] <sidetag> ..."
|
||||
usage = "%prog remove-sidetag [options] <sidetag> ..."
|
||||
usage += "\n(Specify the --help global option for a list of other help options)"
|
||||
parser = ArgumentParser(usage=usage)
|
||||
parser.add_argument("sidetags", help="name of sidetag", nargs="+")
|
||||
opts = parser.parse_args(args)
|
||||
parser = OptionParser(usage=usage)
|
||||
(opts, args) = parser.parse_args(args)
|
||||
|
||||
if len(args) < 1:
|
||||
parser.error("Sidetag argument is required")
|
||||
|
||||
activate_session(session, options)
|
||||
|
||||
session.multicall = True
|
||||
for sidetag in opts.sidetags:
|
||||
for sidetag in args:
|
||||
session.removeSideTag(sidetag)
|
||||
session.multiCall(strict=True)
|
||||
|
||||
|
|
@ -74,14 +79,17 @@ def handle_remove_sidetag(options, session, args):
|
|||
@export_cli
|
||||
def handle_list_sidetags(options, session, args):
|
||||
"List sidetags"
|
||||
usage = "%(prog)s list-sidetags [options]"
|
||||
usage = "%prog list-sidetags [options]"
|
||||
usage += "\n(Specify the --help global option for a list of other help options)"
|
||||
parser = ArgumentParser(usage=usage)
|
||||
parser.add_argument("--basetag", action="store", help="Filter on basetag")
|
||||
parser.add_argument("--user", action="store", help="Filter on user")
|
||||
parser.add_argument("--mine", action="store_true", help="Filter on user")
|
||||
parser = OptionParser(usage=usage)
|
||||
parser.add_option("--basetag", action="store", help="Filter on basetag")
|
||||
parser.add_option("--user", action="store", help="Filter on user")
|
||||
parser.add_option("--mine", action="store_true", help="Filter on user")
|
||||
|
||||
opts = parser.parse_args(args)
|
||||
(opts, args) = parser.parse_args(args)
|
||||
|
||||
if len(args) > 0:
|
||||
parser.error("This command takes no arguments")
|
||||
|
||||
if opts.mine and opts.user:
|
||||
parser.error("Specify only one from --user --mine")
|
||||
|
|
@ -99,19 +107,22 @@ def handle_list_sidetags(options, session, args):
|
|||
@export_cli
|
||||
def handle_edit_sidetag(options, session, args):
|
||||
"Edit sidetag"
|
||||
usage = "%(prog)s edit-sidetag [options] <sidetag>"
|
||||
usage = "%prog edit-sidetag [options] <sidetag>"
|
||||
usage += "\n(Specify the --help global option for a list of other help options)"
|
||||
parser = ArgumentParser(usage=usage)
|
||||
parser.add_argument("sidetag", help="name of sidetag")
|
||||
parser.add_argument("--debuginfo", action="store_true", default=None,
|
||||
help="Generate debuginfo repository")
|
||||
parser.add_argument("--no-debuginfo", action="store_false", dest="debuginfo")
|
||||
parser.add_argument("--rpm-macro", action="append", default=[], metavar="key=value",
|
||||
dest="rpm_macros", help="Set tag-specific rpm macros")
|
||||
parser.add_argument("--remove-rpm-macro", action="append", default=[], metavar="key",
|
||||
dest="remove_rpm_macros", help="Remove rpm macros")
|
||||
parser = OptionParser(usage=usage)
|
||||
parser.add_option("--debuginfo", action="store_true", default=None,
|
||||
help="Generate debuginfo repository")
|
||||
parser.add_option("--no-debuginfo", action="store_false", dest="debuginfo")
|
||||
parser.add_option("--rpm-macro", action="append", default=[], metavar="key=value",
|
||||
dest="rpm_macros", help="Set tag-specific rpm macros")
|
||||
parser.add_option("--remove-rpm-macro", action="append", default=[], metavar="key",
|
||||
dest="remove_rpm_macros", help="Remove rpm macros")
|
||||
|
||||
opts = parser.parse_args(args)
|
||||
(opts, args) = parser.parse_args(args)
|
||||
|
||||
if len(args) != 1:
|
||||
parser.error("Only argument is sidetag")
|
||||
sidetag = args[0]
|
||||
|
||||
if opts.debuginfo is None and not opts.rpm_macros and not opts.remove_rpm_macros:
|
||||
parser.error("At least one option needs to be specified")
|
||||
|
|
@ -133,4 +144,4 @@ def handle_edit_sidetag(options, session, args):
|
|||
if opts.remove_rpm_macros:
|
||||
kwargs['remove_rpm_macros'] = opts.remove_rpm_macros
|
||||
|
||||
session.editSideTag(opts.sidetag, **kwargs)
|
||||
session.editSideTag(sidetag, **kwargs)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue