Module: HTOTConv::CLI

Defined in:
lib/htot_conv/cli.rb

Defined Under Namespace

Classes: ScriptOptions

Class Method Summary collapse

Class Method Details

.main(args = ARGV) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
# File 'lib/htot_conv/cli.rb', line 161

def main(args=ARGV)
  script_opts = HTOTConv::CLI.optparse!(args)
  options = script_opts.options
  from_options = script_opts.from_options
  to_options = script_opts.to_options
  
  inio  = ((args.length > 0) && (args[0] != "-"))? File.open(args[0], "rb") : $stdin
  outio = ((args.length > 1) && (args[1] != "-"))? File.open(args[1], "wb") : $stdout
  
  HTOTConv.convert(inio, options[:from_type], outio, options[:to_type], from_options, to_options)
end

.optparse!(args) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/htot_conv/cli.rb', line 134

def optparse!(args)
  script_opts = ScriptOptions.new
  OptionParser.new do |opts|
    script_opts.define_options(opts)

    begin
      opts.parse!(args.dup)
    rescue OptionParser::ParseError => ex
      $stderr << ex.message << "\n"
      exit 1
    end
  end

  OptionParser.new do |opts|
    script_opts.define_options(opts, true)

    begin
      opts.parse!(args)
    rescue OptionParser::ParseError => ex
      $stderr << ex.message << "\n"
      exit 1
    end
  end
  script_opts.freeze
end