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.



5
6
7
# File 'lib/pluto/cli/opts.rb', line 5

def initialize
  load_shortcuts
end

Instance Method Details

#config_pathObject



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

def config_path
  ## @config_path || '~/.pluto'   --- old code
  @config_path || File.join( Env.home, '.pluto' )
end

#config_path=(value) ⇒ Object



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

def config_path=(value)
  @config_path = value
end

#db_nameObject



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

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

#db_name?Boolean

lets us check if user passed in db settings

Returns:

  • (Boolean)


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

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

#db_pathObject



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

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

#load_shortcutsObject



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

def load_shortcuts
  @shortcuts = YAML.load_file( "#{Pluto.root}/config/pluto.index.yml" )
end

#manifestObject



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

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

#manifest=(value) ⇒ Object



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

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

#map_fetch_shortcut(key) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/pluto/cli/opts.rb', line 72

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



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pluto/cli/opts.rb', line 10

def merge_gli_options!( options={} )
  @verbose = true     if options[:verbose] == true

  @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



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

def output_path
  @output_path || '.'
end

#output_path=(value) ⇒ Object



60
61
62
# File 'lib/pluto/cli/opts.rb', line 60

def output_path=(value)
  @output_path = value
end

#verbose=(value) ⇒ Object



42
43
44
# File 'lib/pluto/cli/opts.rb', line 42

def verbose=(value)
  @verbose = true  # note: always assumes true for now; default is false
end

#verbose?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/pluto/cli/opts.rb', line 46

def verbose?
  @verbose || false
end