class Berkshelf::Cli

Public Class Methods

dispatch(meth, given_args, given_opts, config) click to toggle source
Calls superclass method
# File lib/berkshelf/cli.rb, line 37
def dispatch(meth, given_args, given_opts, config)
  if given_args.length > 1 && !(given_args & Thor::HELP_MAPPINGS).empty?
    command = given_args.first

    if subcommands.include?(command)
      super(meth, [command, "help"].compact, nil, config)
    else
      super(meth, ["help", command].compact, nil, config)
    end
  else
    super
    Berkshelf.formatter.cleanup_hook unless config[:current_command].name == "help"
  end
end
new(*args) click to toggle source
Calls superclass method
# File lib/berkshelf/cli.rb, line 53
def initialize(*args)
  super(*args)

  if @options[:config]
    unless File.exist?(@options[:config])
      raise ConfigNotFound.new(:berkshelf, @options[:config])
    end

    Berkshelf.config = Berkshelf::Config.from_file(@options[:config])
  end

  if @options[:debug]
    ENV["BERKSHELF_DEBUG"] = "true"
    Berkshelf.logger.level = ::Logger::DEBUG
  end

  if @options[:quiet]
    Berkshelf.ui.mute!
  end

  Berkshelf.set_format @options[:format]
  @options = options.dup # unfreeze frozen options Hash from Thor
end

Public Instance Methods

apply(environment_name) click to toggle source
# File lib/berkshelf/cli.rb, line 213
def apply(environment_name)
  unless File.exist?(options[:lockfile])
    raise LockfileNotFound, "No lockfile found at #{options[:lockfile]}"
  end

  lockfile     = Lockfile.from_file(options[:lockfile])
  lock_options = Hash[options].each_with_object({}) { |(k, v), m| m[k.to_sym] = v }

  lockfile.apply(environment_name, lock_options)
end
contingent(name) click to toggle source
# File lib/berkshelf/cli.rb, line 315
def contingent(name)
  berksfile    = Berksfile.from_options(options)
  dependencies = berksfile.cookbooks.select do |cookbook|
    cookbook.dependencies.include?(name)
  end

  if dependencies.empty?
    Berkshelf.formatter.msg "There are no cookbooks in this Berksfile contingent upon '#{name}'."
  else
    Berkshelf.formatter.msg "Cookbooks in this Berksfile contingent upon '#{name}':"
    print_list(dependencies)
  end
end
info(name) click to toggle source
# File lib/berkshelf/cli.rb, line 289
def info(name)
  berksfile = Berksfile.from_options(options)
  cookbook  = berksfile.retrieve_locked(name)
  Berkshelf.formatter.info(cookbook)
end
install() click to toggle source
# File lib/berkshelf/cli.rb, line 129
def install
  berksfile = Berksfile.from_options(options)
  berksfile.install
end
list() click to toggle source
# File lib/berkshelf/cli.rb, line 277
def list
  berksfile = Berksfile.from_options(options)
  Berkshelf.formatter.list(berksfile.list)
end
outdated(*names) click to toggle source
# File lib/berkshelf/cli.rb, line 244
def outdated(*names)
  berksfile = Berksfile.from_options(options)
  outdated  = berksfile.outdated(*names, include_non_satisfying: options[:all])
  Berkshelf.formatter.outdated(outdated)
end
package(path = nil) click to toggle source
# File lib/berkshelf/cli.rb, line 344
def package(path = nil)
  if path.nil?
    path ||= File.join(Dir.pwd, "cookbooks-#{Time.now.to_i}.tar.gz")
  else
    path = File.expand_path(path)
  end

  berksfile = Berksfile.from_options(options)
  berksfile.package(path)
end
show(name) click to toggle source
# File lib/berkshelf/cli.rb, line 302
def show(name)
  berksfile = Berksfile.from_options(options)
  cookbook  = berksfile.retrieve_locked(name)
  Berkshelf.formatter.show(cookbook)
end
update(*cookbook_names) click to toggle source
# File lib/berkshelf/cli.rb, line 149
def update(*cookbook_names)
  berksfile = Berksfile.from_options(options)
  berksfile.update(*cookbook_names)
end
upload(*names) click to toggle source
# File lib/berkshelf/cli.rb, line 190
def upload(*names)
  berksfile = Berksfile.from_options(options)

  options[:freeze]    = !options[:no_freeze]
  options[:validate]  = false if options[:skip_syntax_check]
  berksfile.upload(names, options.each_with_object({}) { |(k, v), m| m[k.to_sym] = v })
end
vendor(path = File.join(Dir.pwd, "berks-cookbooks")) click to toggle source
# File lib/berkshelf/cli.rb, line 374
def vendor(path = File.join(Dir.pwd, "berks-cookbooks"))
  berksfile = Berkshelf::Berksfile.from_options(options)
  berksfile.vendor(path)
end
verify() click to toggle source
# File lib/berkshelf/cli.rb, line 383
def verify
  berksfile = Berksfile.from_options(options)
  berksfile.verify
  Berkshelf.formatter.msg "Verified."
end
version() click to toggle source
# File lib/berkshelf/cli.rb, line 416
def version
  Berkshelf.formatter.version
end
viz() click to toggle source
# File lib/berkshelf/cli.rb, line 408
def viz
  berksfile = Berksfile.from_options(options)
  path = berksfile.viz(options[:outfile], options[:outfile_format])

  Berkshelf.ui.info(path)
end

Private Instance Methods

print_list(cookbooks) click to toggle source

Print a list of the given cookbooks. This is used by various methods like {list} and {contingent}.

@param [Array<CachedCookbook>] cookbooks