Class: Csvsql::CommandRunner
- Inherits:
-
Object
- Object
- Csvsql::CommandRunner
- Defined in:
- lib/csvsql/command_runner.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.run!(argv) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/csvsql/command_runner.rb', line 6 def self.run!(argv) = self.new.parse!(argv) return unless if [:clear_cache] Csvsql.clear_cache! puts "Completed clear cache." return end if [:debug] Csvsql::Tracker.tracker = Csvsql::Tracker.new(Logger.new($stdout)) end Csvsql.execute( [:sql], [:csv_data], use_cache: [:use_cache], batch_rows: [:batch_rows], sql_error_action: 'exit', encoding: [:encoding] ) end |
Instance Method Details
#options ⇒ Object
29 30 31 |
# File 'lib/csvsql/command_runner.rb', line 29 def ||= { csv_paths: [] } end |
#parse!(argv) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/csvsql/command_runner.rb', line 33 def parse!(argv) parser.parse!(argv) [:sql] = argv.last paths = .delete(:csv_paths) [:csv_data] = case paths.size when 0 $stdin when 1 paths.first else paths.each_with_object({}) do |path, r| p, n = path.split(':') if n.nil? || n.empty? puts "You should give #{p} a name, example: #{p}:a_name" return false end r[n] = p end end return end |