Class: RepoManager::TaskAction

Inherits:
AppAction show all
Defined in:
lib/repo_manager/actions/task_action.rb

Overview

Invoke external tasks, normally Thor tasks

Examples:

Usage: repo task TASK [args]


repo task repo_manager:sweep:screenshots /to/some/folder
repo repo_manager:sweep:screenshots /to/some/folder

General task help:


repo help task

Help for specific task


repo task help repo_manager:sweep:screenshots
repo help repo_manager:sweep:screenshots

Display a list of tasks


repo task -T
repo  -T

repo task --tasks
repo --tasks

Returns:

  • (Number)

    exit code from task

Instance Attribute Summary

Attributes inherited from BaseAction

#args, #configuration, #exit_code, #option_parser, #options, #output, #template

CLI actions collapse

Methods inherited from AppAction

#asset_type, #repos

Methods inherited from BaseAction

#after_execute, #asset_options, #asset_type, #assets, #before_execute, #execute, #initialize, #items, #overwrite_output?, #render, #write_to_output

Constructor Details

This class inherits a constructor from RepoManager::BaseAction

Instance Method Details

#helpObject



75
76
77
# File 'lib/repo_manager/actions/task_action.rb', line 75

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

#parse_optionsObject

Add action specific options



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/repo_manager/actions/task_action.rb', line 33

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

  opts.on("--bare", "List task names for CLI completion, implies '--tasks'") do |b|
    options[:bare] = b
    options[:tasks] = true if b
  end

  end
end

#processObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/repo_manager/actions/task_action.rb', line 48

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]
    if options[:bare]
      task_manager.list_bare_tasks
    else
      task_manager.list_tasks
    end
    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