班级内的托尔任务清单?
我已经查遍了(谷歌搜索),但我一生都无法弄清楚如何做到这一点。是否可以获取当前类中定义的雷神任务列表?我正在尝试编写一个方法来确定传递给 thor 的参数是否有效,为此,我需要所有已定义任务的列表。我可以在某个常量中创建一个列表,但如果可能的话,我宁愿使用内置工具。
前任:
#!/usr/bin/env ruby
require 'thor'
class Foo < Thor
desc 'task_1', 'The first task'
def task_1
puts 1
end #task_1
desc 'task_2', 'The second task'
def task_2
puts 2
end #task_2
desc 'check_args', 'Checks that the arguments are valid.', :hide => true
# get a list of the tasks defined in this class and check against ARGV
if !valid
invoke :help
exit
end #if
end #check_args
end #Foo
如果我的问题不够清楚或者我只是把这一切都搞错了,请告诉我:)
谢谢
I have looked ALL over (google searched) and I cannot for the life of me figure out how to do this. Is it possible to get a list of the thor tasks defined in the current class? I'm trying to write a method that determines whether or not the argument(s) passed to thor are valid and to do this, I need a list of all the defined tasks. I could just create a list in some constant but I'd rather use built in tools if possible.
Ex:
#!/usr/bin/env ruby
require 'thor'
class Foo < Thor
desc 'task_1', 'The first task'
def task_1
puts 1
end #task_1
desc 'task_2', 'The second task'
def task_2
puts 2
end #task_2
desc 'check_args', 'Checks that the arguments are valid.', :hide => true
# get a list of the tasks defined in this class and check against ARGV
if !valid
invoke :help
exit
end #if
end #check_args
end #Foo
If my question isn't clear enough or I am just going about this ALL wrong, please let me know :)
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
thor -T 也会列出您的所有任务。
thor -T would list all your tasks as well.
当然,在发布这个问题后,我就明白了。
Foo.tasks 将返回一个哈希值 {task_name => [任务信息数组]}
And of course, right after posting this question, I figure it out.
Foo.tasks would return a hash {task_name => [array of task info]}