Class: Tabula::CLI
- Inherits:
-
Object
- Object
- Tabula::CLI
- Defined in:
- lib/tabula/cli.rb
Overview
Command-line interface for tabula
Constant Summary collapse
- FORMATS =
%w[CSV TSV JSON MARKDOWN].freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #run(args) ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
14 15 16 |
# File 'lib/tabula/cli.rb', line 14 def initialize = end |
Class Method Details
.run(args) ⇒ Object
10 11 12 |
# File 'lib/tabula/cli.rb', line 10 def self.run(args) new.run(args) end |
Instance Method Details
#run(args) ⇒ 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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/tabula/cli.rb', line 18 def run(args) parser = build_parser files = parser.parse(args) if [:help] puts parser return 0 end if [:version] puts "tabula #{Tabula::VERSION}" return 0 end if files.empty? warn 'Error: No PDF file specified' warn parser return 1 end process_files(files) rescue OptionParser::InvalidOption => e warn "Error: #{e.message}" warn parser 1 rescue Tabula::FileNotFoundError => e warn "Error: #{e.message}" warn 'Please check that the file path is correct and the file exists.' 1 rescue Tabula::InvalidOptionsError => e warn "Error: Invalid option - #{e.message}" warn 'Use --help to see available options and their valid values.' 1 rescue Tabula::InvalidPDFError => e warn "Error: Invalid PDF file - #{e.message}" 1 rescue Tabula::PasswordRequiredError => e warn "Error: PDF is password protected - #{e.message}" warn 'Use the -s/--password option to provide the password.' 1 rescue StandardError => e warn "Error: #{e.message}" warn e.backtrace.first(5).join("\n") if [:debug] 1 end |