Class: HMap::Command::Gen

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

Overview

hmap file gen cmd

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Gen

Returns a new instance of Gen.



19
20
21
22
23
24
25
# File 'lib/hmap/command/hmap_gen.rb', line 19

def initialize(argv)
  super
  project_directory = argv.option('project-directory')
  @clean_hmap = argv.flag?('clean-hmap', false)
  project_directory = Dir.pwd if project_directory.nil?
  @project_directory = Pathname.new(project_directory).expand_path
end

Class Method Details

.optionsObject

help



35
36
37
38
39
40
# File 'lib/hmap/command/hmap_gen.rb', line 35

def self.options
  [
    ['--project-directory=/project/dir/', 'The path to the root of the project directory'],
    ['--clean-hmap', 'This option will clean up all hmap-gen setup for hmap.']
  ].concat(super)
end

Instance Method Details

#runObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/hmap/command/hmap_gen.rb', line 42

def run
  name = 'Gen'
  name = 'Clean' if @clean_hmap
  UserInterface.puts("\n[hmapfile] #{name} start")
  unless @project_directory.exist?
    UserInterface.puts("\n[hmapfile] #{name} [ERROR] #{@project_directory} dir not exist!".red)
    return
  end
  HMap::MapFileWriter.new(true, @project_directory, @clean_hmap)
  UserInterface.puts("[hmapfile] #{name} finish")
end

#validate!Object



27
28
29
30
31
32
# File 'lib/hmap/command/hmap_gen.rb', line 27

def validate!
  super
  if @project_directory.nil?
    help! 'error: no input project directory which to use with the `--project-directory` option.'
  end
end