The Rodish::DSL class implements Rodish’s DSL. Blocks passed to Rodish.processor and on/run_on blocks inside those blocks evaluated in the context of an instance of Rodish::DSL.
Each Rodish::DSL instance is bound to a single Rodish::Command and allows the DSL to modify the state of the command.
Methods
Public Class
Public Instance
Public Class methods
Create a new command with the given path and evaluate the given block in the context of a new instance using that command.
# File lib/rodish/dsl.rb 19 def self.command(command_path, &block) 20 command = self::Command.new(command_path) 21 new(command).instance_exec(&block) if block 22 command 23 end
# File lib/rodish/dsl.rb 25 def initialize(command) 26 @command = command 27 end
Public Instance methods
Set the number of arguments supported by this command. The default is 0. To support a fixed number of arguments, pass an Integer. To support a variable number of arguments, pass a Range.
# File lib/rodish/dsl.rb 59 def args(args) 60 @command.num_args = args 61 end
Autoload subcommands from the given directory. Filenames ending in .rb in this directory should be valid subcommands, and requiring the related file should load the subcommand.
You can use this so that your argv parser does not need to load code not needed to support processing the command.
# File lib/rodish/dsl.rb 69 def autoload_subcommand_dir(dir) 70 _autoload_subcommand_dir(@command.subcommands, dir) 71 end
Set the banner for the command execution and subcommand usage.
# File lib/rodish/dsl.rb 35 def banner(banner) 36 @command.banner = banner 37 end
Set the description for the command.
# File lib/rodish/dsl.rb 30 def desc(description) 31 @command.desc = description 32 end
Create a new subcommand with the given name and yield to the block to configure the subcommand.
# File lib/rodish/dsl.rb 75 def on(command_name, &block) 76 _on(@command.subcommands, command_name, &block) 77 end
Set the option parser for the command to based on the provided block, which is executed in the context of a new instance of Rodish::OptionParser. These options are parsed for execuction of both subcommands and the current command.
The banner argument is required and sets the usage string for the command.
If key is given, parsed options will be placed in a subhash using that key.
# File lib/rodish/dsl.rb 49 def options(banner, key: nil, &block) 50 @command.banner = banner 51 @command.option_key = key 52 @command.option_parser = create_option_parser(&block) 53 end
Set the block to run for subcommand execution. Commands should have subcommands and/or a run block, otherwise it is not possible to use the command successfully.
# File lib/rodish/dsl.rb 82 def run(&block) 83 @command.run_block = block 84 end