0

I have a custom Python module installed that I want to modify so that it provides an auto-complete function similar to other bash programs so that when the Tab key is pressed a list of variables is printed out or a value is placed in the terminal. I'm not really running in a traditional sense but rather typing the name of the module which is aliased to run a conda environment yada yada. Is

there anyway to get argparse answer with parameter values? For example: after typing python3 ./module rollback -c and pressing tab could I list out some strings?

#!/usr/bin/env python3

import argparse

parser = argparse.ArgumentParser()

subparsers = parser.add_subparsers(dest='command')

rollback = subparsers.add_parser('rollback', help='Rollback to previous commit')
rollback.add_argument('-c', '--commit', dest='incomingCommitHash', default=None, type=str, required=False, help='Commit to deploy')
bitbyte
  • 1
  • 1
  • `python3 ./module rollback -h` is the only builtin help method. There is some sort of third party completer that can with `argparse` but I haven't used it. – hpaulj Jun 17 '23 at 01:07
  • https://stackoverflow.com/questions/14597466/custom-tab-completion-in-python-argparse. https://pypi.org/project/argcomplete/ – hpaulj Jun 17 '23 at 01:13
  • Thanks that's exactly what I was looking for! – bitbyte Jul 04 '23 at 21:25

0 Answers0