2016-04-11 8 views
1

私はThorといくつかのレーキタスクを書いています。これらのタスクでは、コマンドラインをより堅牢にするためのいくつかの方法オプションを指定していますが、私が実行している問題は、thorが私のコマンドを認識していないということです。私は「オプション」WhatisThorにトール公式ウェブページを踏襲していると私はthor help reverification_task:notifications:resend_to_soft_bounced_emailsThorが私のコマンドラインオプションを認識しないのはなぜですか?

を実行したときにそれが正しく私が見ることを期待するものを出力し

module ReverificationTask 
    class Notifications < Thor 
    option :bounce_threshold, :aliases => '-bt', :desc => 'Sets bounce rate', :required => true, :type => :numeric 
    option :num_email, :aliases => '-e', :desc => 'Sets the amount of email', :required => true, :type => :numeric 

    desc 'resend_to_soft_bounced_emails [BOUNCE_THRESHOLD] [NUM_EMAIL]' 

    def resend_to_soft_bounced_emails(bounce_rate, amount_of_email) 
     Reverification::Process.set_amazon_stat_settings(bounce_rate, amount_of_email) 
     Reverification::Mailer.resend_soft_bounced_notifications 
    end 
    end 
end 

:ここ

は、例えば作業ですコマンドライン引数:

Usage: 
thor reverification_task:notifications:resend_to_soft_bounced_emails [BOUNCE_THRESHOLD] [NUM_EMAIL] -bt, --bounce-threshold=N -e, --num-email=N 

Options: 
    -bt, --bounce-threshold=N # Sets bounce rate 
    -e, --num-email=N   # Sets the amount of email 

私はthor reverification_task:notifications:resend_to_soft_bounced_emails -bt 20 -e 2000を実行すると、これが応答である:

No value provided for required options '--bounce-threshold' 

ここで問題は何ですか?どんな助けでも大歓迎です。ありがとう。

答えて

0

オプションを引数に混ぜただけです。あなたはdef resend_to_soft_bounced_emails(bounce_rate, amount_of_email)で行ったようにあなたは、あなたのトールタスクの定義に引数を追加する場合は、あまりにも、コマンドライン引数としてそれらを呼び出す必要があります:

thor reverification_task:notifications:resend_to_soft_bounced_emails 20 2000 

しかし、あなたはかなりのオプションを使用したい(-接頭辞を使用して、コマンドラインに渡さ)ので、タスク定義から引数を削除し、optionsハッシュを使用してオプションを参照する必要があります。

def resend_to_soft_bounced_emails 
    Reverification::Process.set_amazon_stat_settings(options[:bounce_threshold], 
                options[:num_email]) 
    Reverification::Mailer.resend_soft_bounced_notifications 
end 
関連する問題