module HTOTConv::CLI
Public Class Methods
main(args=ARGV)
click to toggle source
# 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)
click to toggle source
# 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
Private Instance Methods
main(args=ARGV)
click to toggle source
# 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)
click to toggle source
# 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