Class: StructuredDataToSql::CLI
- Inherits:
-
Object
- Object
- StructuredDataToSql::CLI
- Defined in:
- lib/structured_data_to_sql/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(stdin: $stdin, stdout: $stdout, stderr: $stderr) ⇒ CLI
constructor
A new instance of CLI.
- #run(argv) ⇒ Object
Constructor Details
#initialize(stdin: $stdin, stdout: $stdout, stderr: $stderr) ⇒ CLI
Returns a new instance of CLI.
12 13 14 15 16 |
# File 'lib/structured_data_to_sql/cli.rb', line 12 def initialize(stdin: $stdin, stdout: $stdout, stderr: $stderr) @stdin = stdin @stdout = stdout @stderr = stderr end |
Class Method Details
.run(argv, stdin: $stdin, stdout: $stdout, stderr: $stderr) ⇒ Object
8 9 10 |
# File 'lib/structured_data_to_sql/cli.rb', line 8 def self.run(argv, stdin: $stdin, stdout: $stdout, stderr: $stderr) new(stdin:, stdout:, stderr:).run(argv) end |
Instance Method Details
#run(argv) ⇒ Object
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 |
# File 'lib/structured_data_to_sql/cli.rb', line 18 def run(argv) command = argv.shift return print_help if command.nil? || %w[-h --help help].include?(command) return print_version if %w[-v --version version].include?(command) case command when "json" convert_json(argv) when "xml", "mysql-xml" convert_xml(argv) else raise UsageError, "Unknown command #{command.inspect}; expected json or xml" end 0 rescue Json::ParseError, MysqlDumpXml::ParseError => e @stderr.puts("error: #{e.}") 1 rescue ConfigurationError, OptionParser::ParseError => e @stderr.puts("error: #{e.}") 2 rescue Error, SystemCallError, IOError, Zlib::Error => e @stderr.puts("error: #{e.}") 1 end |