Class: Pluto::Opts

Inherits:
Object
  • Object
show all
Defined in:
lib/pluto/cli/opts.rb

Instance Method Summary collapse

Constructor Details

#initializeOpts

Returns a new instance of Opts.



7
8
9
# File 'lib/pluto/cli/opts.rb', line 7

def initialize
  load_shortcuts
end

Instance Method Details

#config_pathObject



81
82
83
84
# File 'lib/pluto/cli/opts.rb', line 81

def config_path
  ## note: defaults to  ~/.pluto
  @config_path || File.join( Env.home, '.pluto' )
end

#config_path=(value) ⇒ Object



77
78
79
# File 'lib/pluto/cli/opts.rb', line 77

def config_path=(value)
  @config_path = value
end

#db_nameObject



55
# File 'lib/pluto/cli/opts.rb', line 55

def db_name()    @db_name || 'pluto.db' ;  end

#db_name?Boolean

lets us check if user passed in db settings

Returns:

  • (Boolean)


52
# File 'lib/pluto/cli/opts.rb', line 52

def db_name?()   @db_name.present? ;  end

#db_pathObject



54
# File 'lib/pluto/cli/opts.rb', line 54

def db_path()    @db_path || '.' ;         end

#debug?Boolean

add debug? alias for verbose

Returns:

  • (Boolean)


65
# File 'lib/pluto/cli/opts.rb', line 65

def debug?()          @verbose || false; end

#error?Boolean

add error? alias for quiet

Returns:

  • (Boolean)


72
# File 'lib/pluto/cli/opts.rb', line 72

def error?()          @quiet || false;  end

#load_shortcutsObject



95
96
97
98
# File 'lib/pluto/cli/opts.rb', line 95

def load_shortcuts
  ### Note: for now shortcuts packed w/ pluto-merge  - move to pluto (this gem??) why? why not?
  @shortcuts = YAML.load_file( "#{PlutoMerge.root}/config/pluto.index.yml" )
end

#manifestObject



59
# File 'lib/pluto/cli/opts.rb', line 59

def manifest()         @manifest || 'blank' ;  end

#manifest=(value) ⇒ Object



58
# File 'lib/pluto/cli/opts.rb', line 58

def manifest=(value)   @manifest = value;  end

#map_fetch_shortcut(key) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/pluto/cli/opts.rb', line 100

def map_fetch_shortcut( key )
  # NB: always returns an array!!!  0,1 or more entries
  # - no value - return empty ary

  ## todo: normalize key???
  value = @shortcuts.fetch( key, nil )

  if value.nil?
    []
  elsif value.kind_of?( String )
    [value]
  else  # assume it's an array already;  ## todo: check if it's an array
    value
  end
end

#merge_gli_options!(options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/pluto/cli/opts.rb', line 12

def merge_gli_options!( options={} )
  ###
  #  todo/check: renamve verbose to debug and quiet to error - why? why not?
  #    use a single (internal) variable for log level - why? why not?

  if options[:verbose] == true   ## debug level
    @verbose = @warn = @quiet = true
  end

  if options[:warn]    == true   ## warn level
    @warn = @quiet = true
    @verbose = false
  end

  if options[:quiet]   == true   ## error level (for now) - why? why not?
    @quiet = true
    @verbose = @warn = false
  end


  @db_path   = options[:dbpath]  if options[:dbpath].present?

  if options[:dbname].present?
    ##########
    # note: c.default_value '<PLANET>.db e.g. ruby.db'
    #  gli2 will set default if present - thus, do NOT set a default value
    #    otherwise it will get set

    @db_name   = options[:dbname]
    puts "setting opts.db_name to '#{options[:dbname]}'"
  end

  @config_path = options[:config]    if options[:config].present?
  @output_path = options[:output]    if options[:output].present?

  @manifest       =   options[:template]  if options[:template].present?
end

#output_pathObject



91
92
93
# File 'lib/pluto/cli/opts.rb', line 91

def output_path
  @output_path || '.'
end

#output_path=(value) ⇒ Object



87
88
89
# File 'lib/pluto/cli/opts.rb', line 87

def output_path=(value)
  @output_path = value
end

#quiet=(value) ⇒ Object

use error/error? - why? why not?



70
# File 'lib/pluto/cli/opts.rb', line 70

def quiet=(value)     @quiet = true;    end

#quiet?Boolean

Returns:

  • (Boolean)


71
# File 'lib/pluto/cli/opts.rb', line 71

def quiet?()          @quiet || false;  end

#verbose=(value) ⇒ Object

# note: always assumes true for now for verbose/quiet/warn; default is false



63
# File 'lib/pluto/cli/opts.rb', line 63

def verbose=(value)   @verbose = true;   end

#verbose?Boolean

Returns:

  • (Boolean)


64
# File 'lib/pluto/cli/opts.rb', line 64

def verbose?()        @verbose || false; end

#warn=(value) ⇒ Object



67
# File 'lib/pluto/cli/opts.rb', line 67

def warn=(value)      @warn = true;     end

#warn?Boolean

Returns:

  • (Boolean)


68
# File 'lib/pluto/cli/opts.rb', line 68

def warn?()           @warn || false;   end