Class: HMap::Command::Reader

Inherits:
HMap::Command show all
Defined in:
lib/hmap/command/hmap_reader.rb

Overview

hmap file reader cmd

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Reader

Returns a new instance of Reader.



18
19
20
21
22
# File 'lib/hmap/command/hmap_reader.rb', line 18

def initialize(argv)
  super
  mapfile_path = argv.option('hmap-path') || ''
  @mapfile_path = Pathname.new(mapfile_path).expand_path
end

Class Method Details

.optionsObject



30
31
32
33
34
# File 'lib/hmap/command/hmap_reader.rb', line 30

def self.options
  [
    ['--hmap-path=/hmap/dir/file', 'The path of the hmap file']
  ].concat(super)
end

Instance Method Details

#runObject



36
37
38
39
40
41
42
43
44
# File 'lib/hmap/command/hmap_reader.rb', line 36

def run
  UserInterface.puts "\n[hmapfile] Reader start\n"
  if File.exist?(@mapfile_path)
    HMap::MapFileReader.new(@mapfile_path)
  else
    UserInterface.puts "\n[hmapfile] Reader input path: #{@mapfile_path} no such file!\n".red
  end
  UserInterface.puts "\n[hmapfile] Reader finish\n"
end

#validate!Object



24
25
26
27
28
# File 'lib/hmap/command/hmap_reader.rb', line 24

def validate!
  super
  # banner! if help?
  raise "[hmapfile] Reader [ERROR]: --hmap-path #{@mapfile_path} no exist".red if @mapfile_path.nil?
end