Class: Prescient::CLI
- Inherits:
-
Object
- Object
- Prescient::CLI
- Defined in:
- lib/prescient/cli.rb
Overview
Command-line interface for common Prescient operations.
Defined Under Namespace
Classes: UsageError
Constant Summary collapse
- FORMATS =
Supported output formats.
['text', 'json'].freeze
Class Method Summary collapse
-
.run(arguments, input: $stdin, output: $stdout, errors: $stderr) ⇒ Integer
Run the CLI and return a process exit status.
Instance Method Summary collapse
-
#initialize(arguments, input:, output:, errors:) ⇒ CLI
constructor
Initialize a CLI runner with injectable streams.
- #run ⇒ Object
Constructor Details
#initialize(arguments, input:, output:, errors:) ⇒ CLI
Initialize a CLI runner with injectable streams.
38 39 40 41 42 43 |
# File 'lib/prescient/cli.rb', line 38 def initialize(arguments, input:, output:, errors:) @arguments = arguments.dup @input = input @output = output @errors = errors end |
Class Method Details
.run(arguments, input: $stdin, output: $stdout, errors: $stderr) ⇒ Integer
Run the CLI and return a process exit status.
22 23 24 25 26 27 28 29 30 |
# File 'lib/prescient/cli.rb', line 22 def self.run(arguments, input: $stdin, output: $stdout, errors: $stderr) new(arguments, input:, output:, errors:).run rescue UsageError, OptionParser::ParseError => e errors.puts "prescient: #{e.}" 2 rescue Prescient::Error => e errors.puts "prescient: #{e.}" 1 end |
Instance Method Details
#run ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/prescient/cli.rb', line 45 def run command = @arguments.shift return print_help(2) unless command case command when 'providers' then providers when 'health' then health when 'generate' then generate when 'embed' then when 'config' then config when 'help', '--help', '-h' then print_help(0) else raise UsageError, "unknown command #{command.inspect}; run 'prescient help'" end end |