[英]Why doesn't Thor recognize my command line option?
I am writing some rake tasks with Thor. 我正在和Thor一起写一些rake任务。 In these thor tasks I am specifying some method options to make the command line more robust but the problem that I am running into is that thor is not recognizing my commands.
在这些thor任务中,我指定了一些方法选项,以使命令行更加健壮,但我遇到的问题是thor无法识别我的命令。
Here is an example task: 这是一个示例任务:
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
I have followed the Thor official web page on 'Options' WhatisThor and when I run thor help reverification_task:notifications:resend_to_soft_bounced_emails
我在“选项” WhatisThor上关注Thor官方网页,当我运行
thor help reverification_task:notifications:resend_to_soft_bounced_emails
reverification_task时thor help reverification_task:notifications:resend_to_soft_bounced_emails
It correctly outputs what I would expect to see in the command line argument: 它正确输出了我期望在命令行参数中看到的内容:
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
When I execute thor reverification_task:notifications:resend_to_soft_bounced_emails -bt 20 -e 2000
this is the response: 当我执行
thor reverification_task:notifications:resend_to_soft_bounced_emails -bt 20 -e 2000
这是响应:
No value provided for required options '--bounce-threshold'
What is the problem here? 这里有什么问题? Any help would be greatly appreciated.
任何帮助将不胜感激。 Thanks.
谢谢。
You just mixed options with arguments. 你只是用参数混合选项。 If you add arguments to your thor task definition, as you did in
def resend_to_soft_bounced_emails(bounce_rate, amount_of_email)
, you need to call them as command line arguments too: 如果您向thor任务定义添加参数,就像在
def resend_to_soft_bounced_emails(bounce_rate, amount_of_email)
,您还需要将它们称为命令行参数:
thor reverification_task:notifications:resend_to_soft_bounced_emails 20 2000
But you rather wanted to use options (passed on the command line with -
prefixes), so you should remove the arguments from your task definition and refer to the options using the options
hash: 但您更愿意使用选项(使用
-
前缀在命令行上传递),因此您应该从任务定义中删除参数并使用options
hash参考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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.