Class: RepoManager::HelpAction

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

Overview

CLI help

Provide help for an action

Examples:

Usage: repo help [action]


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



67
68
69
# File 'lib/repo_manager/actions/help_action.rb', line 67

def help
  super :comment_starting_with => "CLI help", :located_in_file => __FILE__
end

#parse_optionsObject

Add action specific options



22
23
24
25
26
27
28
29
30
# File 'lib/repo_manager/actions/help_action.rb', line 22

def parse_options
  super do |opts|

    opts.on("--actions", "List available actions") do |a|
      options[:actions] = a
    end

  end
end

#processObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/repo_manager/actions/help_action.rb', line 32

def process
  parse_options
  action = args.shift

  if options[:actions]
    AVAILABLE_ACTIONS.each do |act|
      puts act
    end

    exit(0) unless action
  end

  unless action
    puts "no action specified"
    puts "Usage: repo help action | repo --help"
    puts ""
    puts "Where 'action' is one of: #{AVAILABLE_ACTIONS.join(' ')}"

    exit(0)
  end

  action = action.downcase
  unless AVAILABLE_ACTIONS.include?(action)
    puts "invalid help action: #{action}"
    exit(0)
  end

  klass = Object.const_get('RepoManager').const_get("#{action.capitalize}Action")
  app_action = klass.new(['--help'], configuration)
  app_action.option_parser = self.option_parser
  result = app_action.execute

  exit(0)
end