forked from Mirror/pmbootstrap
pmbootstrap newapkbuild: Properly parse arguments (#1320)
* pmbootstrap newapkbuild: Properly parse arguments The `pmbootstrap newapkbuild` action wraps Alpine's `newapkbuild`. We used to directly pass all arguments to `newapkbuild` without verifying in Python whether they make sense or not. However, as `newpakbuild` doesn't do strict sanity checks on the arguments, it is easy to end up with unexpected behavior when using the command for the first time. For example, `newapkbuild` allows either specifying a PKGNAME or SRCURL as last parameter, and also allows setting a PKGNAME with the `-n` parameter. It only makes sense to use that option when passing a SRCURL. With this commit, we duplicate the optins that should be passed through to `newapkbuild` and use argparse to fully sanitize the options and display a help page (`pmbootstrap newapkbuild -h`) that is consistent with the other help pages. Details: * The `-f` (force) flag does not get passed through anymore. Instead we use it in Python to skip asking if an existing aport should be overwritten (the aports are outside of the chroot, so `newapkbuild` can't handle it in a way that makes sense for pmbootstrap). * Output of `newapkbuild` gets redirected to the log file now, as we don't need it to display a help page. * Don't verify the pkgver while creating the new APKBUILD. When passing a SRCURL, the pkgver gets extracted from the end of the URL and may not have a valid format yet (but we want the APKBUILD anyway). * Stored options passed through in `pmb/config/__init__.py` and use it in both `pmb/parse/arguments.py` and `pmb/helpers/frontend.py`. * Only allow `-n` with SRCURL * The postmarketOS aports folder gets specified with `--folder` now. That way the generated help page is much closer to the original one from `newapkbuild`. The default is `main`. * Made the package type flags (CMake, autotools, ...) exclusive so only one of them can be specified
This commit is contained in:
parent
e7c18f6c48
commit
5ea00e0862
4 changed files with 97 additions and 17 deletions
|
@ -143,13 +143,44 @@ def arguments_pkgrel_bump(subparser):
|
|||
|
||||
|
||||
def arguments_newapkbuild(subparser):
|
||||
ret = subparser.add_parser("newapkbuild", help="get a template to package"
|
||||
"""
|
||||
Wrapper for Alpine's "newapkbuild" command.
|
||||
|
||||
Most parameters will get directly passed through, and they are defined in
|
||||
"pmb/config/__init__.py". That way they can be used here and when passing
|
||||
them through in "pmb/helpers/frontend.py". The order of the parameters is
|
||||
kept the same as in "newapkbuild -h".
|
||||
"""
|
||||
sub = subparser.add_parser("newapkbuild", help="get a template to package"
|
||||
" new software")
|
||||
ret.add_argument("folder", help="aports subfolder, where the new aport will"
|
||||
" be located (main, cross, device, ...)")
|
||||
ret.add_argument("args_passed", nargs=argparse.REMAINDER,
|
||||
help="arguments directly passed to Alpine's newapkbuild,"
|
||||
" more information: 'pmbootstrap newapkbuild main -h'")
|
||||
sub.add_argument("--folder", help="set postmarketOS aports folder"
|
||||
" (default: main)", default="main")
|
||||
|
||||
# Passthrough: Strings (e.g. -d "my description")
|
||||
for entry in pmb.config.newapkbuild_arguments_strings:
|
||||
sub.add_argument(entry[0], dest=entry[1], help=entry[2])
|
||||
|
||||
# Passthrough: Package type switches (e.g. -C for CMake)
|
||||
group = sub.add_mutually_exclusive_group()
|
||||
for entry in pmb.config.newapkbuild_arguments_switches_pkgtypes:
|
||||
group.add_argument(entry[0], dest=entry[1], help=entry[2],
|
||||
action="store_true")
|
||||
|
||||
# Passthrough: Other switches (e.g. -c for copying sample files)
|
||||
for entry in pmb.config.newapkbuild_arguments_switches_other:
|
||||
sub.add_argument(entry[0], dest=entry[1], help=entry[2],
|
||||
action="store_true")
|
||||
|
||||
# Force switch
|
||||
sub.add_argument("-f", dest="force", action="store_true",
|
||||
help="force even if directory already exists")
|
||||
|
||||
# Passthrough: PKGNAME[-PKGVER] | SRCURL
|
||||
sub.add_argument("pkgname_pkgver_srcurl",
|
||||
metavar="PKGNAME[-PKGVER] | SRCURL",
|
||||
help="set either the package name (optionally with the"
|
||||
" PKGVER at the end, e.g. 'hello-world-1.0') or the"
|
||||
" download link to the source archive")
|
||||
|
||||
|
||||
def arguments():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue