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.



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

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.



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

def files
  @files
end

Instance Method Details

#add(opt) ⇒ Object



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

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

#pacObject



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

def pac
  @options[:pac]
end

#urlObject



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

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