diff --git a/pmb/helpers/other.py b/pmb/helpers/other.py index c30aee32aaab07e808753a9e186431c5b8883aca..9c1d72113505a638e148f31c1e342fd71907807a 100644 --- a/pmb/helpers/other.py +++ b/pmb/helpers/other.py @@ -24,14 +24,6 @@ import pmb.config import pmb.helpers.run -def getpackagelist(aportsdir): - packages=set() - for dir in os.listdir(aportsdir): - for package in os.listdir('aports/'+dir): - packages.add(package) - return packages - - def folder_size(args, path): """ Run `du` to calculate the size of a folder (this is less code and diff --git a/pmb/parse/arguments.py b/pmb/parse/arguments.py index c61d1f6ced6618103505eb70f38dcc00042408cb..0bb54219cb97cbf7c09512fdd722d692bf2bad0d 100644 --- a/pmb/parse/arguments.py +++ b/pmb/parse/arguments.py @@ -17,6 +17,14 @@ You should have received a copy of the GNU General Public License along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>. """ import argparse +import glob +import os + +try: + import argcomplete +except ImportError: + argcomplete = False + import pmb.config import pmb.parse.arch @@ -219,6 +227,15 @@ def arguments_kconfig(subparser): parser.add_argument("package") +def packagecompleter(prefix, action, parser, parsed_args): + args = parsed_args + pmb.config.merge_with_args(args) + packages = set() + for apkbuild in glob.glob(args.aports + "/*/" + prefix + "*/APKBUILD"): + packages.add(os.path.basename(os.path.dirname(apkbuild))) + return packages + + def arguments(): parser = argparse.ArgumentParser(prog="pmbootstrap") arch_native = pmb.parse.arch.alpine_native() @@ -430,7 +447,9 @@ def arguments(): " is incompatible with how Alpine's abuild handles it.", dest="ignore_depends") for action in [checksum, build, aportgen]: - action.add_argument("packages", nargs="+", metavar="PACKAGES", choices=pmb.helpers.other.getpackagelist("aports")) + argument_packages = action.add_argument("packages", nargs="+") + if argcomplete: + argument_packages.completer = packagecompleter # Action: kconfig_check / apkbuild_parse kconfig_check = sub.add_parser("kconfig_check", help="check, whether all" @@ -459,11 +478,8 @@ def arguments(): help="force even if the file seems to be" " invalid") - try: - import argcomplete + if argcomplete: argcomplete.autocomplete(parser) - except ImportError: - pass # Use defaults from the user's config file args = parser.parse_args()