Class: Stove::Cli
Instance Method Summary collapse
- #execute! ⇒ Object
-
#initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ Cli
constructor
A new instance of Cli.
Constructor Details
#initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ Cli
Returns a new instance of Cli.
8 9 10 |
# File 'lib/stove/cli.rb', line 8 def initialize(argv, stdin=STDIN, stdout=STDOUT, stderr=STDERR, kernel=Kernel) @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel end |
Instance Method Details
#execute! ⇒ Object
12 13 14 15 16 17 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 |
# File 'lib/stove/cli.rb', line 12 def execute! $stdout, $stderr = @stdout, @stderr # Parse the options hash option_parser.parse!(@argv) # Set the log level Stove.log_level = [:log_level] # Parse out the version from ARGV [:version] = @argv.shift # Useful debugging output for when people type the wrong fucking command # and then open an issue like it's somehow my fault log.info("Options: #{options.inspect}") log.info("ARGV: #{@argv.inspect}") # Unless the user specified --no-bump, version is a required argument, so # blow up if we don't get it or if it's not a nice version string if [:bump] raise OptionParser::MissingArgument.new(:version) unless [:version] end # Make a new cookbook object - this will raise an exception if there is # no cookbook at the given path cookbook = Cookbook.new([:path]) # Set the category on the cookbook object if one was given if category = .delete(:category) cookbook.category = category end # Now execute the actual runners (validations and errors might occur) Runner.run(cookbook, ) # If we got this far, everything was successful :) @kernel.exit(0) rescue => e log.error('Stove experienced an error!') log.error(e.class.name) log.error(e.) log.error(e.backtrace.join("\n")) @kernel.exit(e.respond_to?(:exit_code) ? e.exit_code : 500) ensure $stdout, $stderr = STDOUT, STDERR end |