[英]Why doesn't Thor recognize my command line option?
我正在和Thor一起写一些rake任务。 在这些thor任务中,我指定了一些方法选项,以使命令行更加健壮,但我遇到的问题是thor无法识别我的命令。
这是一个示例任务:
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
我在“选项” WhatisThor上关注Thor官方网页,当我运行thor help reverification_task:notifications:resend_to_soft_bounced_emails
reverification_task时thor help reverification_task:notifications:resend_to_soft_bounced_emails
它正确输出了我期望在命令行参数中看到的内容:
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'
这里有什么问题? 任何帮助将不胜感激。 谢谢。
你只是用参数混合选项。 如果您向thor任务定义添加参数,就像在def resend_to_soft_bounced_emails(bounce_rate, amount_of_email)
,您还需要将它们称为命令行参数:
thor reverification_task:notifications:resend_to_soft_bounced_emails 20 2000
但您更愿意使用选项(使用-
前缀在命令行上传递),因此您应该从任务定义中删除参数并使用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.