Module: Jenkins::CLI::Command::InstanceMethods

Defined in:
lib/jenkins/cli/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



130
131
132
# File 'lib/jenkins/cli/command.rb', line 130

def options
  @options
end

Instance Method Details

#parse(args) ⇒ Object

Set up the instance with command-line arguments.

Any arguments from the terminal will be passed to #parse as a whitespace separated list. The default implementation uses Slop to parse this list with the block passed to arguments

Note: If this method returns a falsy value, then the command will not be run.

You can override this instance method if you don’t want to use Slop, or if you want to do some preprocessing before Slop is called. param [Array] args the list of whitespace separated command line arguments return [Object] a truthy value if the parse succeeded and the command can be run.



145
146
147
148
149
150
151
152
153
# File 'lib/jenkins/cli/command.rb', line 145

def parse(args)
  default_banner = "#{self.class.command_name} [options] - #{self.class.description}"
  @options = Slop.new(:help => true, :strict => true,
                      :banner => default_banner, &self.class.slop_block)
  @options.parse(args)
rescue Slop::Error => e
  $stderr.puts e.message
  $stderr.puts @options.help
end

#runObject

Run the command.

This method is invoked immediately after #parse and implements the “meat” of the command. By default, it invokes body specified with #run.

There should generally be no reason to override this, but hey it’s your world! :-)



163
164
165
# File 'lib/jenkins/cli/command.rb', line 163

def run
  self.instance_eval(&self.class.run_block)
end