Class: FlattenDB::CLI
- Inherits:
-
Nuggets::CLI
- Object
- Nuggets::CLI
- FlattenDB::CLI
- Defined in:
- lib/flattendb/cli.rb
Constant Summary collapse
- TYPES =
{ :mysql => { :title => 'MySQL', :opts => lambda { |opts, | opts.on('-x', '--xml', 'Input file is of type XML [This is the default]') { [:type] = :xml } opts.on('-s', '--sql', 'Input file is of type SQL') { [:type] = :sql } } }, :mdb => { :title => 'MS Access', :opts => lambda { |opts, | opts.separator(" NOTE: Repeat '-i' for each .mdb file") } } }
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#type ⇒ Object
Returns the value of attribute type.
75 76 77 |
# File 'lib/flattendb/cli.rb', line 75 def type @type end |
Class Method Details
.defaults ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/flattendb/cli.rb', line 60 def defaults super.merge( :input => '-', :inputs => [], :output => '-', :config => 'config.yaml' ) end |
.execute(type = nil, *args) ⇒ Object
69 70 71 |
# File 'lib/flattendb/cli.rb', line 69 def execute(type = nil, *args) new(nil, type).execute(*args) end |
Instance Method Details
#run(arguments) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/flattendb/cli.rb', line 77 def run(arguments) if type require "flattendb/types/#{type}" else quit 'Database type is required!' end [:input] = if type == :mdb if [:inputs].empty? if arguments.empty? [:inputs] << [:input] else [:inputs].concat(arguments) arguments.clear end end [:inputs].map! { |file| open_file_or_std(file) } else open_file_or_std( [:inputs].last || arguments.shift || [:input] ) end quit unless arguments.empty? [:output] = open_file_or_std([:output], true) FlattenDB[type].to_flat!() end |