Class: EdifactConverter::CommandLineParser

Inherits:
Object
  • Object
show all
Defined in:
lib/edifact_converter/command_line_parser.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.optionsObject



10
11
12
# File 'lib/edifact_converter/command_line_parser.rb', line 10

def options
  @options ||= {}
end

Class Method Details

.parseObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/edifact_converter/command_line_parser.rb', line 52

def parse
  parser.parse!
  if ARGV.size != 1
    puts "Wrong number of arguments, run #{$COMMAND_NAME} -h for a list of possible arguments."
    exit
  end
  options[:input] = Pathname.new ARGV.first
  unless options[:source]
    if options[:input].extname =~ /xml/
      options[:source] = :xml
    else
      options[:source] = :edifact
    end
  end
  options
end

.parserObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/edifact_converter/command_line_parser.rb', line 14

def parser
  @parser ||= begin
    OptionParser.new do|opts|
      opts.banner = "Usage: #{$COMMAND_NAME} [options] file"
      opts.on( '-x', '--xml', 'Convert from Edifact to XML' ) do
        options[:source] = :edifact
      end
      opts.on( '-e', '--edi', 'Convert from XML to Edifact' ) do
        options[:source] = :xml
      end
      opts.on( '-1', '--xml11', 'Only convert to XML 1-1') do
        options[:xml11] = true
      end
      opts.on( '-f', '--format', 'Format edifact output with newlines') do
        options[:format] = true
      end
      opts.on( '--html', 'Only convert to XML 1-1') do
        options[:html] = true
      end
      opts.on( '-l', '--logfile FILE', 'Write log to FILE' ) do |file|
        options[:logfile] = file
      end
      opts.on( '-o', '--output FILE', 'Write output to FILE' ) do |file|
        options[:to_file] = file
      end
      opts.on( '-v', '--version', "Prints version of #{$COMMAND_NAME}") do
        puts "#{$COMMAND_NAME} version #{VERSION}"
        exit
      end
      opts.on( '-h', '--help', 'Display this screen' ) do
        puts opts
        exit
      end
    end
  end

end