Class: OPA::CLI
- Inherits:
-
Object
- Object
- OPA::CLI
- Defined in:
- lib/opa/cli.rb
Constant Summary collapse
- COMMANDS =
%w[pack verify inspect].freeze
Instance Method Summary collapse
-
#initialize(argv) ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
Constructor Details
#initialize(argv) ⇒ CLI
Returns a new instance of CLI.
10 11 12 |
# File 'lib/opa/cli.rb', line 10 def initialize(argv) @argv = argv.dup end |
Instance Method Details
#run ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/opa/cli.rb', line 14 def run if @argv.empty? || %w[-h --help help].include?(@argv.first) print_usage return 0 end if %w[-v --version].include?(@argv.first) $stdout.puts "opa-ruby #{OPA::VERSION}" return 0 end command = @argv.shift unless COMMANDS.include?(command) $stderr.puts "Unknown command: #{command}" $stderr.puts "Run 'opa --help' for usage." return 1 end send("run_#{command}") rescue StandardError => e $stderr.puts "Error: #{e.message}" 1 end |