【问题标题】:Thor task list from within the class?班内的雷神任务列表?
【发布时间】:2012-02-17 00:48:30
【问题描述】:

我已经查看了所有内容(谷歌搜索),但我一生都无法弄清楚如何做到这一点。是否可以获得当前类中定义的雷神任务列表?我正在尝试编写一个方法来确定传递给 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

如果我的问题不够清楚,或者我只是在处理这一切都错了,请告诉我 :)

谢谢

【问题讨论】:

    标签: task thor


    【解决方案1】:

    thor -T 也会列出你的所有任务。

    【讨论】:

      【解决方案2】:

      当然,在发布这个问题之后,我就明白了。

      Foo.tasks 会返回一个哈希 {task_name => [array of task info]}

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-02-28
        相关资源
        最近更新 更多