Class: Pls::Configurator

Inherits:
Object
  • Object
show all
Defined in:
lib/pls/configurator.rb

Overview

Handles input parameters.

Constant Summary collapse

DIC =
[
  ['-p', '--pac package', 'Package name.', String, :pac]
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfigurator

Returns a new instance of Configurator.



24
25
26
27
28
29
30
31
32
33
# File 'lib/pls/configurator.rb', line 24

def initialize
  ARGV << '-h' if ARGV.empty?
  @options = {}
  OptionParser.new do |o|
    o.banner = "Usage: #{File.basename($PROGRAM_NAME)} [options]."
    DIC.each { |f, p, d, t, k| o.on(f, p, t, d) { |i| @options[k] = i } }
    add(o)
  end.parse!
  raise 'Please specify a package name with -p flag.' if pac.nil?
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



11
12
13
# File 'lib/pls/configurator.rb', line 11

def files
  @files
end

Instance Method Details

#add(opt) ⇒ Object



17
18
19
20
21
22
# File 'lib/pls/configurator.rb', line 17

def add(opt)
  opt.on('-v', '--version', 'Show version.') do
    puts "#{File.basename($PROGRAM_NAME)} #{VERSION} #{DATE}"
    exit
  end
end

#pacObject



35
36
37
# File 'lib/pls/configurator.rb', line 35

def pac
  @options[:pac]
end

#urlObject



39
40
41
# File 'lib/pls/configurator.rb', line 39

def url
  'https://registry.npmjs.org'
end