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, #check_arguments, #cli_arguments, #cli_options, #has_arguments?, #has_options?, #help_banner, #opt, #parse, #stop_on, #trollop_parser

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



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

def arguments
  @arguments
end

#leftoversObject (readonly)

Returns the value of attribute leftovers.



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

def leftovers
  @leftovers
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Class Method Details

.extended(othermodule) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# 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
        othermodule.send(:parse_argv)
        othermodule.send(:run)
      end
    end
  end
end

Instance Method Details

#ancestorsObject



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

def ancestors ; [self] ; end

#description(string = nil) ⇒ Object

Set the description for this script

Parameters:

  • string (String) (defaults to: nil)

    Description/Banner/Help text



23
24
25
26
27
28
29
# File 'lib/climate/script.rb', line 23

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

#has_subcommands?Boolean

Returns:

  • (Boolean)


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

def has_subcommands? ; false ; end

#nameObject



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

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

#parse_argvObject



31
32
33
# File 'lib/climate/script.rb', line 31

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