Class: Stove::Cli
- Inherits:
-
Object
- Object
- Stove::Cli
- Defined in:
- lib/stove/cli.rb
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.
6 7 8 |
# File 'lib/stove/cli.rb', line 6 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
10 11 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/stove/cli.rb', line 10 def execute! $stdout, $stderr = @stdout, @stderr # Parse the options hash option_parser.parse!(@argv) # Login command if @argv.first == 'login' if [:username].nil? || [:username].to_s.strip.empty? raise "Missing argument `--username'!" end if [:key].nil? || [:key].to_s.strip.empty? raise "Missing argument `--key'!" end Config.username = [:username] Config.key = [:key] Config.endpoint = [:endpoint] unless [:endpoint].nil? Config.save @stdout.puts "Successfully saved config to `#{Config.__path__}'!" @kernel.exit(0) return end # Override configs Config.endpoint = [:endpoint] if [:endpoint] Config.username = [:username] if [:username] Config.key = [:key] if [:key] Config.artifactory = [:artifactory] if [:artifactory] Config.artifactory_key = [:artifactory_key] if [:artifactory_key] Config.ssl_verify = [:ssl_verify] # Set the log level Stove.log_level = [:log_level] # Useful debugging output for when people type the wrong fucking command # and then open an issue like it's somehow my fault Stove::Log.info("Options: #{.inspect}") Stove::Log.info("ARGV: #{@argv.inspect}") # Make a new cookbook object - this will raise an exception if there is # no cookbook at the given path cookbook = Cookbook.new([:path]) # Now execute the actual runners (validations and errors might occur) runner = Runner.new(cookbook, ) runner.run # If we got this far, everything was successful :) @kernel.exit(0) rescue => e Stove::Log.init($stderr) Stove::Log.error('Stove experienced an error!') Stove::Log.error(e.class.name) Stove::Log.error(e.) Stove::Log.error(e.backtrace.join("\n")) @kernel.exit(e.respond_to?(:exit_code) ? e.exit_code : 500) ensure $stdout, $stderr = STDOUT, STDERR end |