✨ Shtab : Pythonアプリケーションの自動補完を提供する
3385 ワード
私はほとんどの人々は、bashやPythonのアプリケーションを書いている/ツールは、ターミナルコマンドラインから実行するには
だから、どのようにあなたのPythonアプリケーションの同じ魔法を行うことができますか?
最も簡単な答えはShtab - コードを解析し、必要なファイルを生成できるPythonライブラリ
このツールはCasper のメンテナンスを自動化するDVC プロジェクト
さて、十分な話をしましょう🎥.
Python CLIアプリケーションでは
some useful stuff
. これらのプログラムは通常いくつかのパラメータとオプションを受け入れます.そして、あなたが押すことができるとき、それは本当に涼しいですTAB
キーとコマンドが期待するオプションのリストを取得します.$ git ch<TAB>
...
checkout -- checkout branch or paths to working tree
checkout-index -- copy files from index to working directory
🦾 It seems to be a minor thing but it boosts your productivity significantly! Enough for a search query
productivity terminal autocomplete
to generate almost a million results.
だから、どのようにあなたのPythonアプリケーションの同じ魔法を行うことができますか?
最も簡単な答えはShtab - コードを解析し、必要なファイルを生成できるPythonライブラリ
bash
or zsh
あなたのツールに同じ強力な機能を与えるシェル💥 .このツールはCasper のメンテナンスを自動化するDVC プロジェクト
😱 Every time a new feature is added, maintainers and contributors have to update tab completion scripts for multiple supported shells. At best, it's a pain, and at worst, error-prone.
さて、十分な話をしましょう🎥.
Python CLIアプリケーションでは
argparse
, docopt
, or argopt
単にパーサオブジェクトをshtab
( CLIかPython APIを経由して)いずれかのタブでスクリプトを生成します.以下のように簡単です.$ shtab --shell=bash myprogram.main.parser
またはPythonでimport shtab
print(shtab.complete(parser, shell="bash"))
それでGit for Data's 端末では完成がインストールされているかのように見えます.% dvc <TAB>
Completing dvc commands
add -- Track data files or directories with DVC.
cache -- Manage cache settings.
checkout -- Checkout data files from cache.
commit -- Save changed data to cache and update DVC-files.
completion -- Prints out shell tab completion scripts.
At Top: Hit TAB for more, or the character to insert
私はあなたが役に立つことを願って、このlibはいくつかの時間を節約します!いつものように、プロジェクトAを与える⭐️ 感謝するauthor と問題トラッカーやコメントへようこそ👇 質問があれば.Reference
この問題について(✨ Shtab : Pythonアプリケーションの自動補完を提供する), 我々は、より多くの情報をここで見つけました https://dev.to/shcheklein/shtab-provide-autocomplete-for-your-python-app-3npdテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol