开发者

How to get 'command-line intellisense' (TAB TAB) to work with a Python script?

开发者 https://www.devze.com 2023-04-02 08:02 出处:网络
My Python script accepts a number of options s开发者_StackOverflowuch as the following: python ./Controller.py create 1

My Python script accepts a number of options s开发者_StackOverflowuch as the following:

python ./Controller.py create 1
python ./Controller.py destroy

Is there anyways I can get intellisense to work in the command-line? For instance, typing the following:

python ./Controller.py <TAB><TAB>

should give the following:

create - <description>
destroy - <description>

Is there a good way to do this in a portable way?


For bash, this feature is known as Bash Completion. Other shells may have similar functionality. Here's the official reference for it: Programmable Completion.

It's important to keep in mind this is a feature of the shell, not of Python or the script you're invoking.


AFAIK, the only way to do something along these lines is to provide help when the user enters something like python ./Controller.py -h. Take a look at the argparse module for hints on how to incorporate it into your script.

0

精彩评论

暂无评论...
验证码 换一张
取 消