0

3 つの質問があります。

1)。引数の順序を気にせずに、この python コマンドライン プログラムを使用できるようにしたいと考えています。以前は sys.argv を使用していましたが、ユーザーにこのスクリプトを次のように使用 させました。mypyscript.py create indexname http://localhost:9260 clientMap.json これには、ユーザーが順序を覚えておく必要があります。私はこのようなものが欲しいです: mypyscript.py -i indexname -c create -f clientMap.json -u http://localhost:9260 私が注文をどのように傷つけたかに注意してください.

2)。コード内の条件付きロジックとして使用するプログラム内のコマンドライン変数は? args.command-type 経由でアクセスする必要がありますか? ダッシュ大丈夫?

3)。file-to-index のみがオプションのパラメーターです。オプションの = True パラメータなどを add_argument に渡すことはできますか? どうすれば対処できますか?

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("-c","--command-type", help="The command to run against ElasticSearch are one of these: create|delete|status")
parser.add_argument("-i","--index_name", help="Name of ElasticSearch index to run the command against")
parser.add_argument("-u", "--elastic-search-url", help="Base URl of ElasticSearch")
parser.add_argument("-f", "--file_to_index", default = 'false', help="The file name of the index map")

args = parser.parse_args()


print args.elastic_search_url
4

1 に答える 1