2016-10-26 7 views
0

コマンドグループに問題があります。私はthis guideに従っています。クリックコマンドグループの実行に関する問題

» ~/cli.py upload_translations --template-id=xxxxx --lang=ja 
Template ID: sdf 
Langcode: asdf 
Error: no such option: --template-id 
  1. はなぜクリックオプションを要求している:

    #!/usr/bin/env python 
    
    import click 
    
    
    @click.group() 
    @click.option("--template-id", prompt="Template ID", help="The template to use.") 
    @click.option("--lang", prompt="Langcode", help="The language to use.") 
    def cli(template_id, lang): 
        pass 
    
    
    @cli.command() 
    @click.argument('template-id') 
    @click.argument('lang') 
    def upload_translations(template_id, lang): 
        pass 
    
    
    if __name__ == "__main__": 
        cli() 
    

    が実行これが問題の原因は?私はすでにコマンドラインでそれを渡しています!

  2. エラー:no such option: --template-idが表示されるのはなぜですか?

答えて

1

--template-idオプションは、upload_translationsコマンドのオプションではありません。ベースcliのオプションです。だから、あなたはそれが好きで呼び出します。

./cli.py --template-id=xxxxxx --lang=ja upload_translations ... 

をまた、あなたはcli上とupload_translationsの両方--langオプションがあります。これはこれも有効だろう意味:少し混乱だ

./cli.py --template-id=xxxxxx upload_translations --lang=ja ... 

--langのオプションを削除したり、実際には同じものでない場合は、これらの2つのコマンドのいずれかに異なる名前を付けることができます。

+0

ご意見ありがとうございます。私は引数とオプション、およびグループ引数/オプションとコマンド引数/オプションについて混乱しました。私はグループがコマンドにオプションを渡すことができたと思った。私はLinuxのコマンドにクリックがやっているように動作するのに慣れていないので少し奇妙です。クリックすると、コマンドの前にいくつかのオプション/引数が与えられ、コマンドの後ろにいくつかのオプション/引数があると思われます。 Linuxのコマンドは、オプションの場所に関して厳密ではありません。 – dangonfast

関連する問題