Module: Subcommands

Defined in:
lib/aws-carb/monkey_patches.rb

Overview

override the output from optparse to be a bit more aesthetically pleasing

Instance Method Summary collapse

Instance Method Details

#command(*names) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/aws-carb/monkey_patches.rb', line 61

def command *names
  name = names.shift

  @commands ||= {}
  @aliases  ||= {}

  names.each { |n| @aliases[n.to_s] = name.to_s } if names.length > 0

  opt = lambda do
    OptionParser.new do |opts|
      yield opts
      opts.banner << "OPTIONS"
    end
  end

  @commands[name.to_s] = opt
end


46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/aws-carb/monkey_patches.rb', line 46

def print_actions
  subcommand_help = "#{'SUBCOMMAND'.colorize({:color => :white, :mode => :bold})}\n"

  @commands.each_pair do |c, opt|
    subcommand_help << "\n    #{c}              - #{opt.call.description}"
  end

  unless @aliases.empty?
    subcommand_help << "\n\naliases: \n"
    @aliases.each_pair { |name, val| subcommand_help << "   #{name} - #{val}\n"  }
  end

  subcommand_help << "\n\n    help <command>      - for more information on a specific command\n\n"
end