Module: Rodish::Plugins::PostCommands::CommandMethods

Defined in:
lib/rodish/plugins/post_commands.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#post_bannerObject

A usage banner for any post subcommands.



65
66
67
# File 'lib/rodish/plugins/post_commands.rb', line 65

def post_banner
  @post_banner
end

#post_option_keyObject

Similar to option_key, but for post options instead of normal subcommands.



62
63
64
# File 'lib/rodish/plugins/post_commands.rb', line 62

def post_option_key
  @post_option_key
end

#post_option_parserObject

The post option parser for the current command. Called only before dispatching to post subcommands.



58
59
60
# File 'lib/rodish/plugins/post_commands.rb', line 58

def post_option_parser
  @post_option_parser
end

#post_subcommandsObject (readonly)

A hash of post subcommands for the command. Keys are post subcommand name strings.



54
55
56
# File 'lib/rodish/plugins/post_commands.rb', line 54

def post_subcommands
  @post_subcommands
end

Instance Method Details

#each_banner {|post_banner| ... } ⇒ Object

Also yield the post banner

Yields:



112
113
114
115
116
# File 'lib/rodish/plugins/post_commands.rb', line 112

def each_banner
  super
  yield post_banner if post_banner
  nil
end

#each_subcommand(names = [].freeze, &block) ⇒ Object

Also yield each post subcommand, recursively.



106
107
108
109
# File 'lib/rodish/plugins/post_commands.rb', line 106

def each_subcommand(names = [].freeze, &block)
  super
  _each_subcommand(names, @post_subcommands, &block)
end

#freezeObject

Freeze all post subcommands and the post option parsers in addition to the command itself.



74
75
76
77
78
79
# File 'lib/rodish/plugins/post_commands.rb', line 74

def freeze
  @post_subcommands.each_value(&:freeze)
  @post_subcommands.freeze
  @post_option_parser.freeze
  super
end

#initialize(command_path) ⇒ Object



67
68
69
70
# File 'lib/rodish/plugins/post_commands.rb', line 67

def initialize(command_path)
  super
  @post_subcommands = {}
end

#post_subcommand(name) ⇒ Object

Returns a Command instance for the named post subcommand. This will autoload the post subcommand if not already loaded.



120
121
122
# File 'lib/rodish/plugins/post_commands.rb', line 120

def post_subcommand(name)
  _subcommand(@post_subcommands, name)
end

#run(context, options, argv) ⇒ Object Also known as: run_post_subcommand

Run a post subcommand using the given context (generally self), options, and argv. Usually called inside a run block, after shifting one or more values off the given argv:

run do |argv, opts, command|
@name = argv.shift
command.run(self, opts, argv)
end


89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/rodish/plugins/post_commands.rb', line 89

def run(context, options, argv)
  begin
    process_options(argv, options, @post_option_key, @post_option_parser)
  rescue ::OptionParser::ParseError => e
    raise CommandFailure.new(e.message, self)
  end

  arg = argv[0]
  if arg && @post_subcommands[arg]
    process_subcommand(@post_subcommands, context, options, argv)
  else
    process_command_failure(arg, @post_subcommands, "post ")
  end
end