forked from Mirror/pmbootstrap
pmb.parse.arguments: common func for packages arg (!1872)
Create add_packages_add() function, so we don't need to write the three lines for adding the "packages" argument to an action with proper autocompletion.
This commit is contained in:
parent
a021d1924c
commit
fbbcc1c26f
1 changed files with 17 additions and 10 deletions
|
@ -273,9 +273,7 @@ def arguments_repo_missing(subparser):
|
||||||
def arguments_lint(subparser):
|
def arguments_lint(subparser):
|
||||||
lint = subparser.add_parser("lint", help="run quality checks on pmaports"
|
lint = subparser.add_parser("lint", help="run quality checks on pmaports"
|
||||||
" (required to pass CI)")
|
" (required to pass CI)")
|
||||||
argument_packages = lint.add_argument("packages", nargs="*")
|
add_packages_arg(lint, nargs="*")
|
||||||
if argcomplete:
|
|
||||||
argument_packages.completer = package_completer
|
|
||||||
|
|
||||||
|
|
||||||
def package_completer(prefix, action, parser, parsed_args):
|
def package_completer(prefix, action, parser, parsed_args):
|
||||||
|
@ -293,6 +291,12 @@ def kernel_completer(prefix, action, parser, parsed_args):
|
||||||
return [package.replace("linux-", "", 1) for package in packages]
|
return [package.replace("linux-", "", 1) for package in packages]
|
||||||
|
|
||||||
|
|
||||||
|
def add_packages_arg(subparser, name="packages", *args, **kwargs):
|
||||||
|
arg = subparser.add_argument(name, *args, **kwargs)
|
||||||
|
if argcomplete:
|
||||||
|
arg.completer = package_completer
|
||||||
|
|
||||||
|
|
||||||
def arguments():
|
def arguments():
|
||||||
parser = argparse.ArgumentParser(prog="pmbootstrap")
|
parser = argparse.ArgumentParser(prog="pmbootstrap")
|
||||||
arch_native = pmb.parse.arch.alpine_native()
|
arch_native = pmb.parse.arch.alpine_native()
|
||||||
|
@ -506,15 +510,21 @@ def arguments():
|
||||||
" (even if supported by device)", dest="sparse",
|
" (even if supported by device)", dest="sparse",
|
||||||
action="store_false")
|
action="store_false")
|
||||||
|
|
||||||
# Action: checksum / aportgen / build
|
# Action: checksum
|
||||||
checksum = sub.add_parser("checksum", help="update aport checksums")
|
checksum = sub.add_parser("checksum", help="update aport checksums")
|
||||||
checksum.add_argument("--verify", action="store_true", help="download"
|
checksum.add_argument("--verify", action="store_true", help="download"
|
||||||
" sources and verify that the checksums of the"
|
" sources and verify that the checksums of the"
|
||||||
" APKBUILD match, instead of updating them")
|
" APKBUILD match, instead of updating them")
|
||||||
|
add_packages_arg(checksum, nargs="+")
|
||||||
|
|
||||||
|
# Action: aportgen
|
||||||
aportgen = sub.add_parser("aportgen", help="generate a postmarketOS"
|
aportgen = sub.add_parser("aportgen", help="generate a postmarketOS"
|
||||||
" specific package build recipe (aport/APKBUILD)")
|
" specific package build recipe (aport/APKBUILD)")
|
||||||
aportgen.add_argument("--fork-alpine", help="fork the alpine upstream package",
|
aportgen.add_argument("--fork-alpine", help="fork the alpine upstream package",
|
||||||
action="store_true", dest="fork_alpine")
|
action="store_true", dest="fork_alpine")
|
||||||
|
add_packages_arg(aportgen, nargs="+")
|
||||||
|
|
||||||
|
# Action: build
|
||||||
build = sub.add_parser("build", help="create a package for a"
|
build = sub.add_parser("build", help="create a package for a"
|
||||||
" specific architecture")
|
" specific architecture")
|
||||||
build.add_argument("--arch", choices=arch_choices, default=None,
|
build.add_argument("--arch", choices=arch_choices, default=None,
|
||||||
|
@ -543,19 +553,16 @@ def arguments():
|
||||||
build.add_argument("--envkernel", action="store_true",
|
build.add_argument("--envkernel", action="store_true",
|
||||||
help="Create an apk package from the build output of"
|
help="Create an apk package from the build output of"
|
||||||
" a kernel compiled with envkernel.sh.")
|
" a kernel compiled with envkernel.sh.")
|
||||||
for action in [checksum, build, aportgen]:
|
add_packages_arg(build, nargs="+")
|
||||||
argument_packages = action.add_argument("packages", nargs="+")
|
|
||||||
if argcomplete:
|
|
||||||
argument_packages.completer = package_completer
|
|
||||||
|
|
||||||
# Action: apkbuild_parse
|
# Action: apkbuild_parse
|
||||||
apkbuild_parse = sub.add_parser("apkbuild_parse")
|
apkbuild_parse = sub.add_parser("apkbuild_parse")
|
||||||
apkbuild_parse.add_argument("packages", nargs="*")
|
add_packages_arg(apkbuild_parse, nargs="*")
|
||||||
|
|
||||||
# Action: apkindex_parse
|
# Action: apkindex_parse
|
||||||
apkindex_parse = sub.add_parser("apkindex_parse")
|
apkindex_parse = sub.add_parser("apkindex_parse")
|
||||||
apkindex_parse.add_argument("apkindex_path")
|
apkindex_parse.add_argument("apkindex_path")
|
||||||
apkindex_parse.add_argument("package", default=None, nargs="?")
|
add_packages_arg(apkindex_parse, "package", nargs="?")
|
||||||
|
|
||||||
# Action: config
|
# Action: config
|
||||||
config = sub.add_parser("config",
|
config = sub.add_parser("config",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue