lib/berkshelf/cli.rb in berkshelf-0.4.0 vs lib/berkshelf/cli.rb in berkshelf-0.5.0.rc1
- old
+ new
@@ -1,6 +1,7 @@
require 'thor'
+require 'thor/monkies'
require 'berkshelf'
module Berkshelf
# @author Jamie Winsor <jamie@vialstudios.com>
class Cli < Thor
@@ -9,16 +10,15 @@
super
Berkshelf.formatter.cleanup_hook unless config[:current_task].name == "help"
end
end
- def initialize(*)
- super
- # JW TODO: Replace Chef::Knife::UI with our own UI class
- ::Berkshelf.ui = Chef::Knife::UI.new(STDOUT, STDERR, STDIN, {})
- ::Berkshelf.config_path = @options[:config]
- ::Berkshelf.set_format @options[:format]
+ def initialize(*args)
+ super(*args)
+ self.shell = Berkshelf.ui
+ Berkshelf.config_path = @options[:config]
+ Berkshelf.set_format @options[:format]
@options = options.dup # unfreeze frozen options Hash from Thor
end
namespace "berkshelf"
@@ -34,52 +34,54 @@
desc: "Path to Knife or Chef configuration to use.",
aliases: "-c",
banner: "PATH"
class_option :format,
type: :string,
+ default: "human",
desc: "Output format to use.",
aliases: "-F",
banner: "FORMAT"
- method_option :shims,
- type: :string,
- default: nil,
- lazy_default: File.join(Dir.pwd, "cookbooks"),
- desc: "Create a directory of shims pointing to Cookbook Versions.",
- banner: "PATH"
- method_option :without,
+ method_option :except,
type: :array,
- default: Array.new,
desc: "Exclude cookbooks that are in these groups.",
- aliases: "-w"
+ aliases: "-e"
+ method_option :only,
+ type: :array,
+ desc: "Only cookbooks that are in these groups.",
+ aliases: "-o"
method_option :berksfile,
type: :string,
default: File.join(Dir.pwd, Berkshelf::DEFAULT_FILENAME),
desc: "Path to a Berksfile to operate off of.",
aliases: "-b",
banner: "PATH"
+ method_option :path,
+ type: :string,
+ desc: "Path to install cookbooks to (i.e. vendor/cookbooks).",
+ aliases: "-p",
+ banner: "PATH"
desc "install", "Install the Cookbooks specified by a Berksfile or a Berksfile.lock."
def install
- unless options[:shims].nil?
- options[:shims] = File.expand_path(options[:shims])
- end
-
berksfile = ::Berkshelf::Berksfile.from_file(options[:berksfile])
berksfile.install(options)
end
method_option :berksfile,
type: :string,
default: File.join(Dir.pwd, Berkshelf::DEFAULT_FILENAME),
desc: "Path to a Berksfile to operate off of.",
aliases: "-b",
banner: "PATH"
- method_option :without,
+ method_option :except,
type: :array,
- default: Array.new,
desc: "Exclude cookbooks that are in these groups.",
- aliases: "-w"
+ aliases: "-e"
+ method_option :only,
+ type: :array,
+ desc: "Only cookbooks that are in these groups.",
+ aliases: "-o"
desc "update", "Update all Cookbooks and their dependencies specified by a Berksfile to their latest versions."
def update
Lockfile.remove!
invoke :install
end
@@ -88,15 +90,18 @@
type: :string,
default: File.join(Dir.pwd, Berkshelf::DEFAULT_FILENAME),
desc: "Path to a Berksfile to operate off of.",
aliases: "-b",
banner: "PATH"
- method_option :without,
+ method_option :except,
type: :array,
- default: Array.new,
desc: "Exclude cookbooks that are in these groups.",
- aliases: "-w"
+ aliases: "-e"
+ method_option :only,
+ type: :array,
+ desc: "Only cookbooks that are in these groups.",
+ aliases: "-o"
method_option :freeze,
type: :boolean,
default: false,
desc: "Freeze the uploaded cookbooks so that they cannot be overwritten"
option :force,
@@ -105,10 +110,16 @@
desc: "Upload all cookbooks even if a frozen one exists on the target Chef Server"
desc "upload", "Upload the Cookbooks specified by a Berksfile or a Berksfile.lock to a Chef Server."
def upload
Berkshelf.load_config
berksfile = ::Berkshelf::Berksfile.from_file(options[:berksfile])
- berksfile.upload(Chef::Config[:chef_server_url], options)
+
+ berksfile.upload(
+ server_url: Chef::Config[:chef_server_url],
+ client_name: Chef::Config[:node_name],
+ client_key: Chef::Config[:client_key],
+ organization: ChefAPILocation.extract_organization(Chef::Config[:chef_server_url])
+ )
end
desc "init [PATH]", "Prepare a local path to have its Cookbook dependencies managed by Berkshelf."
def init(path = Dir.pwd)
if File.chef_cookbook?(path)