Module: Envin::CLI

Extended by:
CLI
Included in:
CLI
Defined in:
lib/envin/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionObject (readonly)

Returns the value of attribute option.



6
7
8
# File 'lib/envin/cli.rb', line 6

def option
  @option
end

Instance Method Details

#parse(args = ARGV) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/envin/cli.rb', line 7

def parse(args=ARGV)
  opts = {}

  parser = OptionParser.new do |opt_parser|
    opt_parser.on '-f', '--filepath FILENAME', 'file path' do |arg|
      opts[:filepath] = File.expand_path(arg)
    end

    opt_parser.on '-p', '--prefix PREFIX', 'env prefix' do |arg|
      opts[:prefix] = arg
    end

    opt_parser.on '-r', '--root-element ELEMENT', 'root element' do |arg|
      opts[:rootelement] = arg
    end

    opt_parser.on '-o', '--output FILENAME', 'root element' do |arg|
      opts[:targetfile] = arg
    end
  end

  parser.on_tail "-h", "--help", "Show help" do
    puts parser
    die 1
  end

  parser.parse!(args)
  @option = opts
end

#runObject



37
38
39
40
41
42
43
# File 'lib/envin/cli.rb', line 37

def run
  if !option[:filepath] || !option[:prefix]
    puts "File path & prefix is required"
    exit(1)
  end
  Converter.overwrite(source_file: option[:filepath], prefix: option[:prefix], root_element: option[:rootelement], target_file: option[:targetfile] )
end