class Kitchen::CLI
The command line runner for Kitchen
.
@author Fletcher Nichol <fnichol@nichol.ca>
Constants
- MAX_CONCURRENCY
The maximum number of concurrent instances that can run–which is a bit high
Attributes
Public Class Methods
Sets the logging method_options @api private
# File lib/kitchen/cli.rb, line 83 def self.log_options method_option :log_level, aliases: "-l", desc: "Set the log level (debug, info, warn, error, fatal)" method_option :log_overwrite, desc: "Set to false to prevent log overwriting each time Test Kitchen runs", type: :boolean method_option :color, type: :boolean, lazy_default: $stdout.tty?, desc: "Toggle color output for STDOUT logger" end
Constructs a new instance.
# File lib/kitchen/cli.rb, line 66 def initialize(*args) super $stdout.sync = true @loader = Kitchen::Loader::YAML.new( project_config: ENV["KITCHEN_YAML"] || ENV["KITCHEN_YML"], local_config: ENV["KITCHEN_LOCAL_YAML"] || ENV["KITCHEN_LOCAL_YML"], global_config: ENV["KITCHEN_GLOBAL_YAML"] || ENV["KITCHEN_GLOBAL_YML"] ) @config = Kitchen::Config.new( loader: @loader ) @config.log_level = Kitchen.env_log unless Kitchen.env_log.nil? @config.log_overwrite = Kitchen.env_log_overwrite unless Kitchen.env_log_overwrite.nil? end
Sets the test_base_path
method_options @api private
# File lib/kitchen/cli.rb, line 98 def self.test_base_path method_option :test_base_path, aliases: "-t", desc: "Set the base path of the tests" end
Private Class Methods
Ensure the any failing commands exit non-zero.
@return [true] you die always on failure @api private
# File lib/kitchen/cli.rb, line 321 def exit_on_failure? true end
Public Instance Methods
# File lib/kitchen/cli.rb, line 300 def console perform("console", "console") end
# File lib/kitchen/cli.rb, line 140 def diagnose(*args) update_config! perform("diagnose", "diagnose", args, loader: @loader) end
# File lib/kitchen/cli.rb, line 272 def doctor(*args) update_config! perform("doctor", "doctor", args) end
# File lib/kitchen/cli.rb, line 283 def exec(*args) update_config! perform("exec", "exec", args) end
# File lib/kitchen/cli.rb, line 118 def list(*args) update_config! perform("list", "list", args) end
# File lib/kitchen/cli.rb, line 255 def login(*args) update_config! perform("login", "login", args) end
# File lib/kitchen/cli.rb, line 262 def package(*args) update_config! perform("package", "package", args) end
# File lib/kitchen/cli.rb, line 295 def sink perform("sink", "sink") end
# File lib/kitchen/cli.rb, line 247 def test(*args) update_config! ensure_initialized perform("test", "test", args) end
# File lib/kitchen/cli.rb, line 289 def version puts "Test Kitchen version #{Kitchen::VERSION}" end
Private Instance Methods
If auto_init option is active, invoke the init generator.
@api private
# File lib/kitchen/cli.rb, line 404 def ensure_initialized yaml = ENV["KITCHEN_YAML"] || ENV["KITCHEN_YML"] || ".kitchen.yml" if options[:auto_init] && !File.exist?(yaml) banner "Invoking init as '#{yaml}' file is missing" invoke "init" end end
Validate the log level from the config / CLI
options, defaulting to :info if the supplied level is empty or invalid
@api private
# File lib/kitchen/cli.rb, line 365 def log_level return unless options[:log_level] return @log_level if @log_level level = options[:log_level].downcase.to_sym unless valid_log_level?(level) level = :info banner "WARNING - invalid log level specified: " \ "\"#{options[:log_level]}\" - reverting to :info log level." end @log_level = level end
@return [Logger] the common logger @api private
# File lib/kitchen/cli.rb, line 330 def logger Kitchen.logger end
Update and finalize options for logging, concurrency, and other concerns.
@api private
# File lib/kitchen/cli.rb, line 337 def update_config! @config.log_level = log_level if log_level unless options[:log_overwrite].nil? @config.log_overwrite = options[:log_overwrite] end @config.colorize = options[:color] unless options[:color].nil? if options[:test_base_path] # ensure we have an absolute path @config.test_base_path = File.absolute_path(options[:test_base_path]) end @config.debug = options[:debug] # Now that we have required configs, lets create our file logger Kitchen.logger = Kitchen.default_file_logger( log_level, options[:log_overwrite] ) update_parallel! end
Set parallel concurrency options for Thor
@api private
# File lib/kitchen/cli.rb, line 389 def update_parallel! if options[:parallel] # warn here in a future release when option is used @options = Thor::CoreExt::HashWithIndifferentAccess.new(options.to_hash) if options[:parallel] && !options[:concurrency] options[:concurrency] = MAX_CONCURRENCY end options.delete(:parallel) options.freeze end end
Check to whether a provided log level is valid
@api private
# File lib/kitchen/cli.rb, line 382 def valid_log_level?(level) !Util.to_logger_level(level).nil? end