なしトールコマンドを実行します。Rubyは - 私は、スクリプトを実行するには、このコマンドを使用する必要があり、引数
$ruby file.rb keyword --format oneline --no-country-code --api-key=API
、format
、no-country-code
、api-key
はthor
オプションです。 keyword
は私のメソッドで引数です:
class TwitterTrendReader < Thor
method_option :'api-key', :required => true
method_option :format
method_option :'no-country-code', :type => :boolean
def execute (keyword)
#read file then display the results matching `keyword`
end
default_task :execute
end
問題はkeyword
は、私はkeyword
せずにコマンドを実行した場合、スクリプトはそれ以外の場合は、ファイル内のすべてのエントリを印刷する必要があり、オプションであり、それが唯一のエントリを表示しますkeyword
と一致します。
ので、私はこのコードを持っている:
if ARGV.empty?
TwitterTrendReader.start ''
else
TwitterTrendReader.start ARGV
end
それは唯一私がkeyword
を指定するときに動作しますがkeyword
せずに、私はこれを取得:
$ruby s3493188_p3.rb --api-key="abC9hsk9"
ERROR: "s3493188_p3.rb execute" was called with no arguments
Usage: "s3493188_p3.rb [keyword] --format oneline --no-country-code --api-key=API-KEY"
は、だから、適切な方法は何を教えてください私は議論を任意にすることができました。ありがとうございました! def execute (keyword)
の
それは非常に機能します。どうもありがとうございます! –