lib/berkshelf/cli.rb in berkshelf-3.0.0.beta6 vs lib/berkshelf/cli.rb in berkshelf-3.0.0.beta7
- old
+ new
@@ -137,12 +137,12 @@
Berkshelf.formatter.deprecation "`berks install --path [PATH}` has been replaced by `berks vendor`."
Berkshelf.formatter.deprecation "Re-run your command as `berks vendor [PATH]` or see `berks help vendor`."
exit(1)
end
- berksfile = Berkshelf::Berksfile.from_file(options[:berksfile])
- berksfile.install(options)
+ berksfile = Berksfile.from_options(options)
+ berksfile.install
end
method_option :berksfile,
type: :string,
default: Berkshelf::DEFAULT_FILENAME,
@@ -157,17 +157,12 @@
type: :array,
desc: 'Only cookbooks that are in these groups.',
aliases: '-o'
desc 'update [COOKBOOKS]', 'Update the cookbooks (and dependencies) specified in the Berksfile'
def update(*cookbook_names)
- berksfile = Berksfile.from_file(options[:berksfile])
-
- update_options = {
- cookbooks: cookbook_names
- }.merge(options).symbolize_keys
-
- berksfile.update(update_options)
+ berksfile = Berksfile.from_options(options)
+ berksfile.update(*cookbook_names)
end
method_option :berksfile,
type: :string,
default: Berkshelf::DEFAULT_FILENAME,
@@ -203,11 +198,11 @@
type: :boolean,
default: false,
desc: 'Halt uploading and exit if the Chef Server has a frozen version of the cookbook(s).'
desc 'upload [COOKBOOKS]', 'Upload the cookbook specified in the Berksfile to the Chef Server'
def upload(*cookbook_names)
- berksfile = Berkshelf::Berksfile.from_file(options[:berksfile])
+ berksfile = Berksfile.from_options(options)
options[:cookbooks] = cookbook_names
options[:freeze] = !options[:no_freeze]
options[:validate] = false if options[:skip_syntax_check]
@@ -228,11 +223,11 @@
def apply(environment_name)
unless File.exist?(options[:lockfile])
raise LockfileNotFound, "No lockfile found at #{options[:lockfile]}"
end
- lockfile = Berkshelf::Lockfile.from_file(options[:lockfile])
+ lockfile = Lockfile.from_file(options[:lockfile])
lock_options = Hash[options].symbolize_keys
lockfile.apply(environment_name, lock_options)
end
@@ -249,14 +244,13 @@
method_option :only,
type: :array,
desc: 'Only cookbooks that are in these groups.',
aliases: '-o'
desc 'outdated [COOKBOOKS]', 'List dependencies that have new versions available that satisfy their constraints'
- def outdated(*cookbook_names)
- berksfile = Berkshelf::Berksfile.from_file(options[:berksfile])
- options[:cookbooks] = cookbook_names
- outdated = berksfile.outdated(options.symbolize_keys)
+ def outdated(*names)
+ berksfile = Berksfile.from_options(options)
+ outdated = berksfile.outdated(*names)
if outdated.empty?
Berkshelf.formatter.msg "All cookbooks up to date!"
else
Berkshelf.formatter.msg "The following cookbooks have newer versions:"
@@ -279,13 +273,21 @@
type: :string,
default: Berkshelf::DEFAULT_FILENAME,
desc: 'Path to a Berksfile to operate off of.',
aliases: '-b',
banner: 'PATH'
- desc 'list', 'List all cookbooks and their dependencies specified by your Berksfile'
+ method_option :except,
+ type: :array,
+ desc: 'Exclude cookbooks that are in these groups.',
+ aliases: '-e'
+ method_option :only,
+ type: :array,
+ desc: 'Only cookbooks that are in these groups.',
+ aliases: '-o'
+ desc 'list', 'List cookbooks and their dependencies specified by your Berksfile'
def list
- berksfile = Berksfile.from_file(options[:berksfile])
+ berksfile = Berksfile.from_options(options)
Berkshelf.formatter.list(berksfile.list)
end
method_option :berksfile,
type: :string,
@@ -293,31 +295,32 @@
desc: "Path to a Berksfile to operate off of.",
aliases: "-b",
banner: "PATH"
desc "show [COOKBOOK]", "Display name, author, copyright, and dependency information about a cookbook"
def show(name)
- berksfile = Berksfile.from_file(options[:berksfile])
- cookbook = berksfile.retrieve_locked(berksfile.find!(name))
+ berksfile = Berksfile.from_options(options)
+ cookbook = berksfile.retrieve_locked(name)
Berkshelf.formatter.show(cookbook)
end
method_option :berksfile,
type: :string,
default: Berkshelf::DEFAULT_FILENAME,
desc: 'Path to a Berksfile to operate off of.',
aliases: '-b',
banner: 'PATH'
- desc 'contingent COOKBOOK', 'List all cookbooks that depend on the given cookbook'
+ desc 'contingent COOKBOOK', 'List all cookbooks that depend on the given cookbook in your Berksfile'
def contingent(name)
- berksfile = Berksfile.from_file(options[:berksfile])
- dependencies = Berkshelf.ui.mute { berksfile.install }.sort
- dependencies = dependencies.select { |cookbook| cookbook.dependencies.include?(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 contingent upon '#{name}' defined in this Berksfile"
+ Berkshelf.formatter.msg "There are no cookbooks in this Berksfile contingent upon '#{name}'."
else
- Berkshelf.formatter.msg "Cookbooks in this Berksfile contingent upon #{name}:"
+ Berkshelf.formatter.msg "Cookbooks in this Berksfile contingent upon '#{name}':"
print_list(dependencies)
end
end
method_option :berksfile,
@@ -340,12 +343,12 @@
path ||= File.join(Dir.pwd, "cookbooks-#{Time.now.to_i}.tar.gz")
else
path = File.expand_path(path)
end
- berksfile = Berkshelf::Berksfile.from_file(options[:berksfile])
- berksfile.package(path, options)
+ berksfile = Berksfile.from_options(options)
+ berksfile.package(path)
end
method_option :except,
type: :array,
desc: 'Exclude cookbooks that are in these groups.',
@@ -360,12 +363,12 @@
desc: 'Path to a Berksfile to operate off of.',
aliases: '-b',
banner: 'PATH'
desc "vendor [PATH]", "Vendor the cookbooks specified by the Berksfile into a directory"
def vendor(path = File.join(Dir.pwd, "berks-cookbooks"))
- berksfile = Berkshelf::Berksfile.from_file(options[:berksfile])
- berksfile.vendor(path, options)
+ berksfile = Berkshelf::Berksfile.from_options(options)
+ berksfile.vendor(path)
end
desc 'version', 'Display version and copyright information'
def version
Berkshelf.formatter.version
@@ -385,10 +388,10 @@
# methods like {list} and {contingent}.
#
# @param [Array<CachedCookbook>] cookbooks
#
def print_list(cookbooks)
- Array(cookbooks).each do |cookbook|
+ Array(cookbooks).sort.each do |cookbook|
Berkshelf.formatter.msg " * #{cookbook.cookbook_name} (#{cookbook.version})"
end
end
end
end