Class: Clue

Inherits:
Object
  • Object
show all
Includes:
Arguments, CLI, Options, Streams
Defined in:
lib/clue.rb,
lib/clue.rb,
lib/clue/version.rb

Defined Under Namespace

Modules: Arguments, CLI, Options, Streams

Constant Summary collapse

VERSION =
'1.1.0'

Constants included from Streams

Streams::RECOGNIZED_STREAMS, Streams::STREAMS_SYMBOLS

Instance Attribute Summary collapse

Attributes included from Streams

#stderr, #stdin, #stdout

Attributes included from Options

#options, #singular_options

Attributes included from CLI

#command, #dry_run, #verbose

Attributes included from Arguments

#arguments

Instance Method Summary collapse

Methods included from Streams

#cli_streams, #init_streams, #set_stream, #set_streams

Methods included from Options

#add_option, #add_options, #add_singular_option, #add_singular_options, #cli_options, #init_options, #options_as_array, #parse_options

Methods included from CLI

#call, #cli_command, #cli_command_array, #print

Methods included from Arguments

#add_argument, #add_arguments, #cli_arguments, #init_arguments, #parse_arguments

Constructor Details

#initialize(*args) ⇒ Clue

Store command name, parse & store args

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/clue.rb', line 18

def initialize(*args)
  hsh = args.last.kind_of?(Hash) && args.pop || {}
  raise ArgumentError, 'there should be at most one command' unless args.size <= 1
  self.command = args.pop

  before_initialize(command, hsh) if self.respond_to?(:before_initialize)

  self.verbose = hsh.delete(:verbose)
  self.dry_run = hsh.delete(:dry_run)

  init_config hsh.delete(:config)
  init_options hsh[:options]
  init_arguments hsh[:arguments]
  init_streams hsh

  after_initialize(command, hsh) if self.respond_to?(:after_initialize)
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



15
16
17
# File 'lib/clue.rb', line 15

def config
  @config
end

Instance Method Details

#init_config(config = {}) ⇒ Object

Handles config



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/clue.rb', line 37

def init_config(config = {})
  @config = {
    :between_arguments      => ' ',
    :between_options        => ' ',
    :between_streams        => ' ',
    :option_value_separator => ' ',
    :option_prefix          => '--',
    :option_delimiter       => "'",
    :stream_delimiter       => "'"
  }

  @config.merge!(config) if config
end