module Rodish::Plugins::PostCommands::CommandMethods

  1. lib/rodish/plugins/post_commands.rb

Public Instance Aliases

run_post_subcommand -> run

Attributes

post_banner [RW]

A usage banner for any post subcommands.

post_option_key [RW]

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

post_option_parser [RW]

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

post_subcommands [R]

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

Public Class methods

new(command_path)
[show source]
   # File lib/rodish/plugins/post_commands.rb
67 def initialize(command_path)
68   super
69   @post_subcommands = {}
70 end

Public Instance methods

each_banner()

Also yield the post banner

[show source]
    # File lib/rodish/plugins/post_commands.rb
112 def each_banner
113   super
114   yield post_banner if post_banner
115   nil
116 end
each_subcommand(names = [].freeze, &block)

Also yield each post subcommand, recursively.

[show source]
    # File lib/rodish/plugins/post_commands.rb
106 def each_subcommand(names = [].freeze, &block)
107   super
108   _each_subcommand(names, @post_subcommands, &block)
109 end
freeze()

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

[show source]
   # File lib/rodish/plugins/post_commands.rb
74 def freeze
75   @post_subcommands.each_value(&:freeze)
76   @post_subcommands.freeze
77   @post_option_parser.freeze
78   super
79 end
post_subcommand(name)

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

[show source]
    # File lib/rodish/plugins/post_commands.rb
120 def post_subcommand(name)
121   _subcommand(@post_subcommands, name)
122 end
run(context, options, argv)

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
[show source]
    # File lib/rodish/plugins/post_commands.rb
 89 def run(context, options, argv)
 90   begin
 91     process_options(argv, options, @post_option_key, @post_option_parser)
 92   rescue ::OptionParser::InvalidOption => e
 93     raise CommandFailure.new(e.message, self)
 94   end
 95 
 96   arg = argv[0]
 97   if arg && @post_subcommands[arg]
 98     process_subcommand(@post_subcommands, context, options, argv)
 99   else
100     process_command_failure(arg, @post_subcommands, "post ")
101   end
102 end