Class: Rangu::CLI
- Inherits:
-
Object
- Object
- Rangu::CLI
- Defined in:
- lib/rangu/cli.rb
Constant Summary collapse
- SUCCESS =
0- ERROR =
1- USAGE_ERROR =
2
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(stdin:, stdout:, stderr:) ⇒ CLI
constructor
A new instance of CLI.
- #run(arguments) ⇒ Object
Constructor Details
#initialize(stdin:, stdout:, stderr:) ⇒ CLI
Returns a new instance of CLI.
16 17 18 19 20 |
# File 'lib/rangu/cli.rb', line 16 def initialize(stdin:, stdout:, stderr:) @stdin = stdin @stdout = stdout @stderr = stderr end |
Class Method Details
.run(arguments, stdin: $stdin, stdout: $stdout, stderr: $stderr) ⇒ Object
12 13 14 |
# File 'lib/rangu/cli.rb', line 12 def self.run(arguments, stdin: $stdin, stdout: $stdout, stderr: $stderr) new(stdin:, stdout:, stderr:).run(arguments) end |
Instance Method Details
#run(arguments) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rangu/cli.rb', line 22 def run(arguments) = {} parser = option_parser() positional = parser.parse(arguments.dup) return print_help(parser) if [:help] return print_version if [:version] source = resolve_source(, positional, parser) source ? execute(source) : USAGE_ERROR rescue OptionParser::ParseError => e report_usage(e., parser) USAGE_ERROR end |