Class: Producer::Core::CLI
- Inherits:
-
Object
- Object
- Producer::Core::CLI
- Defined in:
- lib/producer/core/cli.rb
Constant Summary collapse
- ArgumentError =
Class.new(::ArgumentError)
- USAGE =
"Usage: #{File.basename $0} [options] [recipes]".freeze
- EX_USAGE =
64
- EX_SOFTWARE =
70
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdin ⇒ Object
readonly
Returns the value of attribute stdin.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Class Method Summary collapse
Instance Method Summary collapse
- #evaluate_recipes ⇒ Object
-
#initialize(args, stdin: $stdin, stdout: $stdout, stderr: $stderr) ⇒ CLI
constructor
A new instance of CLI.
- #parse_arguments! ⇒ Object
- #run(worker: Worker.new(@env)) ⇒ Object
Constructor Details
#initialize(args, stdin: $stdin, stdout: $stdout, stderr: $stderr) ⇒ CLI
Returns a new instance of CLI.
33 34 35 36 37 38 39 |
# File 'lib/producer/core/cli.rb', line 33 def initialize(args, stdin: $stdin, stdout: $stdout, stderr: $stderr) @arguments = args @stdin = stdin @stdout = stdout @stderr = stderr @env = build_env end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
31 32 33 |
# File 'lib/producer/core/cli.rb', line 31 def arguments @arguments end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
31 32 33 |
# File 'lib/producer/core/cli.rb', line 31 def env @env end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
31 32 33 |
# File 'lib/producer/core/cli.rb', line 31 def stderr @stderr end |
#stdin ⇒ Object (readonly)
Returns the value of attribute stdin.
31 32 33 |
# File 'lib/producer/core/cli.rb', line 31 def stdin @stdin end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
31 32 33 |
# File 'lib/producer/core/cli.rb', line 31 def stdout @stdout end |
Class Method Details
.run!(arguments, stdin: $stdin, stdout: $stdout, stderr: $stderr) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/producer/core/cli.rb', line 12 def run!(arguments, stdin: $stdin, stdout: $stdout, stderr: $stderr) cli = new(arguments, stdin: stdin, stdout: stdout, stderr: stderr) begin cli.parse_arguments! cli.run rescue ArgumentError => e stderr.puts e. exit EX_USAGE rescue StandardError => e ef = ErrorFormatter.new( debug: cli.env.debug?, force_cause: [RecipeEvaluationError] ) stderr.puts ef.format e exit EX_SOFTWARE end end |
Instance Method Details
#evaluate_recipes ⇒ Object
52 53 54 |
# File 'lib/producer/core/cli.rb', line 52 def evaluate_recipes @arguments.map { |e| Recipe::FileEvaluator.evaluate(e, @env) } end |
#parse_arguments! ⇒ Object
41 42 43 44 |
# File 'lib/producer/core/cli.rb', line 41 def parse_arguments! option_parser.parse!(@arguments) fail ArgumentError, option_parser if @arguments.empty? end |