forked from Mirror/pmbootstrap
Implement bash tab completion
This commit is contained in:
parent
d53550cdc6
commit
7eaf9de000
6 changed files with 31 additions and 71 deletions
|
@ -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="+")
|
||||
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,6 +478,9 @@ def arguments():
|
|||
help="force even if the file seems to be"
|
||||
" invalid")
|
||||
|
||||
if argcomplete:
|
||||
argcomplete.autocomplete(parser, always_complete_options="long")
|
||||
|
||||
# Use defaults from the user's config file
|
||||
args = parser.parse_args()
|
||||
pmb.config.merge_with_args(args)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue