Class: DBF::CLI
- Inherits:
-
Object
- Object
- DBF::CLI
- Defined in:
- lib/dbf/cli.rb
Constant Summary collapse
- USAGE =
<<~HELP usage: dbf [-h|-s|-a|-c|-r] filename -h = print this message -v = print the DBF gem version -s = print summary information -a = create an ActiveRecord::Schema -r = create a Sequel migration -c = export as CSV HELP
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(argv, stdout: $stdout, stderr: $stderr) ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
Constructor Details
#initialize(argv, stdout: $stdout, stderr: $stderr) ⇒ CLI
Returns a new instance of CLI.
21 22 23 24 25 |
# File 'lib/dbf/cli.rb', line 21 def initialize(argv, stdout: $stdout, stderr: $stderr) @argv = argv.dup @stdout = stdout @stderr = stderr end |
Class Method Details
.run(argv, stdout: $stdout, stderr: $stderr) ⇒ Object
17 18 19 |
# File 'lib/dbf/cli.rb', line 17 def self.run(argv, stdout: $stdout, stderr: $stderr) new(argv, stdout: stdout, stderr: stderr).run end |
Instance Method Details
#run ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/dbf/cli.rb', line 27 def run params = OptionParser.new.getopts(@argv, 'h', 's', 'a', 'c', 'r', 'v') if params['v'] print_version elsif params['h'] print_help else filename = @argv.shift return missing_filename unless filename action = %w[a r s c].find { |flag| params[flag] } case action when 'a' then print_ar_schema(filename) when 'r' then print_sequel_schema(filename) when 's' then print_summary(filename) when 'c' then print_csv(filename) end end 0 rescue DBF::FileNotFoundError => e @stderr.puts "DBF::FileNotFoundError: #{e.}" 1 end |