Sha256: a393c72bccdc6ba981931016b2a778dbbb3c7989fa11028bc61c5b53d13bf09c

Contents?: true

Size: 1.58 KB

Versions: 2

Compression:

Stored size: 1.58 KB

Contents

module RepoManager

  # @group CLI actions
  #
  # Invoke external tasks, normally Thor tasks
  #
  # @example Usage: repo task TASK [args]
  #
  #      repo task repo_manager:sweep:screenshots /to/some/folder
  #      repo repo_manager:sweep:screenshots /to/some/folder
  #
  # @example General task help:
  #
  #      repo help task
  #
  # @example Help for specific task
  #
  #      repo task help repo_manager:sweep:screenshots
  #      repo help repo_manager:sweep:screenshots
  #
  # @example Display a list of tasks
  #
  #      repo task -T
  #      repo  -T
  #
  #      repo task --tasks
  #      repo --tasks
  #
  # @return [Number] exit code from task
  class TaskAction < AppAction

    # Add action specific options
    def parse_options
      super(:raise_on_invalid_option => false, :parse_base_options => false) do |opts|

      opts.on("-T", "--tasks", "List tasks") do |t|
        options[:tasks] = t
      end

      end
    end

    def process
      # Thor actions can include toxic side effects,
      # keep the namespace clean until needed
      require 'repo_manager/tasks/task_manager'
      task_manager = RepoManager::TaskManager.new(configuration)

      if options[:tasks]
        task_manager.list_tasks
        return 0
      end

      raise "task name required" if args.empty?

      target = args.shift

      if target == "help"
        target = args.shift
        task_manager.task_help(target)
      else
        task_manager.invoke(target, args)
      end
    end

    def help
      super(:comment_starting_with => "Invoke", :located_in_file => __FILE__)
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
repo_manager-0.7.2 lib/repo_manager/actions/task_action.rb
repo_manager-0.7.1 lib/repo_manager/actions/task_action.rb