Module: Climate::Script

Includes:
ParsingMethods
Defined in:
lib/climate/script.rb

Overview

Module that you can extend any object with to turn it in to a climate script. See the readme for intended usage, but follows the same pattern as the command, with the exception that it does not allow subcommands

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ParsingMethods

#arg, #cli_arguments, #cli_options, #conflicting_options, #conflicts, #dependent_options, #depends, #has_argument?, #has_arguments?, #has_multi_argument?, #has_options?, #has_required_argument?, #opt, #parse, #parse_arguments, #stop_on, #trollop_parser

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



39
40
41
# File 'lib/climate/script.rb', line 39

def arguments
  @arguments
end

#leftoversObject (readonly)

Returns the value of attribute leftovers.



39
40
41
# File 'lib/climate/script.rb', line 39

def leftovers
  @leftovers
end

#optionsObject (readonly)

Returns the value of attribute options.



39
40
41
# File 'lib/climate/script.rb', line 39

def options
  @options
end

Class Method Details

.extended(othermodule) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/climate/script.rb', line 8

def self.extended(othermodule)
  if @included.nil?
    @included = true
    at_exit do
      Climate.with_standard_exception_handling do
        begin
          othermodule.send(:parse_argv)
        rescue Trollop::HelpNeeded => e
          raise HelpNeeded.new(othermodule)
        end
        othermodule.send(:run)
      end
    end
  end
end

Instance Method Details

#ancestorsObject



41
# File 'lib/climate/script.rb', line 41

def ancestors ; [self] ; end

#command_nameObject



42
# File 'lib/climate/script.rb', line 42

def command_name ; File.basename($CLIMATE_PROGRAM_NAME || $PROGRAM_NAME) ; end

#description(string = nil) ⇒ Object

Set the description for this script

Parameters:

  • string (String) (defaults to: nil)

    Description/Banner/Help text



27
28
29
30
31
32
33
# File 'lib/climate/script.rb', line 27

def description(string=nil)
  if string.nil?
    @description
  else
    @description = string
  end
end

#has_subcommands?Boolean

Returns:

  • (Boolean)


44
# File 'lib/climate/script.rb', line 44

def has_subcommands? ; false ; end

#parse_argvObject



35
36
37
# File 'lib/climate/script.rb', line 35

def parse_argv
  @arguments, @options, @leftovers = self.parse(ARGV)
end