Class: Berkshelf::Cli
- Defined in:
- lib/berkshelf/cli.rb,
lib/berkshelf/commands/shelf.rb,
lib/berkshelf/commands/test_command.rb
Defined Under Namespace
Classes: Runner
Class Method Summary collapse
Instance Method Summary collapse
- #apply(environment_name) ⇒ Object
- #contingent(name) ⇒ Object
- #cookbook(name, path = nil) ⇒ Object
- #info(name) ⇒ Object
- #init(path = '.') ⇒ Object
-
#initialize(*args) ⇒ Cli
constructor
A new instance of Cli.
- #install ⇒ Object
- #list ⇒ Object
- #outdated(*names) ⇒ Object
- #package(path = nil) ⇒ Object
- #search(name) ⇒ Object
- #show(name) ⇒ Object
- #update(*cookbook_names) ⇒ Object
- #upload(*names) ⇒ Object
- #vendor(path = File.join(Dir.pwd, "berks-cookbooks")) ⇒ Object
- #verify ⇒ Object
- #version ⇒ Object
- #viz ⇒ Object
Constructor Details
#initialize(*args) ⇒ Cli
Returns a new instance of Cli.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/berkshelf/cli.rb', line 58 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 = .dup # unfreeze frozen options Hash from Thor end |
Class Method Details
.dispatch(meth, given_args, given_opts, config) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/berkshelf/cli.rb', line 42 def dispatch(meth, given_args, given_opts, config) if given_args.length > 1 && !(given_args & Thor::HELP_MAPPINGS).empty? command = given_args.first if self.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 |
Instance Method Details
#apply(environment_name) ⇒ Object
226 227 228 229 230 231 232 233 234 235 |
# File 'lib/berkshelf/cli.rb', line 226 def apply(environment_name) unless File.exist?([:lockfile]) raise LockfileNotFound, "No lockfile found at #{[:lockfile]}" end lockfile = Lockfile.from_file([:lockfile]) = Hash[].symbolize_keys lockfile.apply(environment_name, ) end |
#contingent(name) ⇒ Object
338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/berkshelf/cli.rb', line 338 def contingent(name) berksfile = Berksfile.() 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 |
#cookbook(name, path = nil) ⇒ Object
434 435 436 437 438 439 440 441 442 443 444 |
# File 'lib/berkshelf/cli.rb', line 434 def cookbook(name, path = nil) Berkshelf.formatter.deprecation <<EOF This command is being deprecated in favor of `chef generate cookbook` and will soon return an error. Please use `chef generate cookbook` instead of this command. EOF path = File.join(Dir.pwd, name) if path.nil? Berkshelf.formatter.deprecation '--git is now the default' if [:git] Berkshelf.formatter.deprecation '--vagrant is now the default' if [:vagrant] Berkshelf::CookbookGenerator.new([path, name], ).invoke_all end |
#info(name) ⇒ Object
312 313 314 315 316 |
# File 'lib/berkshelf/cli.rb', line 312 def info(name) berksfile = Berksfile.() cookbook = berksfile.retrieve_locked(name) Berkshelf.formatter.info(cookbook) end |
#init(path = '.') ⇒ Object
271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/berkshelf/cli.rb', line 271 def init(path = '.') Berkshelf.formatter.deprecation <<EOF This command is being deprecated in favor of `chef generate cookbook` and will soon return an error. Please use `chef generate cookbook` instead of this command. EOF Berkshelf.formatter.deprecation '--git is now the default' if [:git] Berkshelf.formatter.deprecation '--vagrant is now the default' if [:vagrant] Berkshelf::InitGenerator.new([path], ).invoke_all Berkshelf.formatter.msg 'Successfully initialized' end |
#install ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/berkshelf/cli.rb', line 134 def install if [:path] # TODO: Remove in Berkshelf 4.0 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 = Berksfile.() berksfile.install end |
#list ⇒ Object
300 301 302 303 |
# File 'lib/berkshelf/cli.rb', line 300 def list berksfile = Berksfile.() Berkshelf.formatter.list(berksfile.list) end |
#outdated(*names) ⇒ Object
252 253 254 255 256 |
# File 'lib/berkshelf/cli.rb', line 252 def outdated(*names) berksfile = Berksfile.() outdated = berksfile.outdated(*names) Berkshelf.formatter.outdated(outdated) end |
#package(path = nil) ⇒ Object
367 368 369 370 371 372 373 374 375 376 |
# File 'lib/berkshelf/cli.rb', line 367 def package(path = nil) if path.nil? path ||= File.join(Dir.pwd, "cookbooks-#{Time.now.to_i}.tar.gz") else path = File.(path) end berksfile = Berksfile.() berksfile.package(path) end |
#search(name) ⇒ Object
264 265 266 267 268 |
# File 'lib/berkshelf/cli.rb', line 264 def search(name) source = Source.new([:source]) cookbooks = source.search(name) Berkshelf.formatter.search(cookbooks) end |
#show(name) ⇒ Object
325 326 327 328 329 |
# File 'lib/berkshelf/cli.rb', line 325 def show(name) berksfile = Berksfile.() cookbook = berksfile.retrieve_locked(name) Berkshelf.formatter.show(cookbook) end |
#update(*cookbook_names) ⇒ Object
161 162 163 164 |
# File 'lib/berkshelf/cli.rb', line 161 def update(*cookbook_names) berksfile = Berksfile.() berksfile.update(*cookbook_names) end |
#upload(*names) ⇒ Object
202 203 204 205 206 207 208 209 |
# File 'lib/berkshelf/cli.rb', line 202 def upload(*names) berksfile = Berksfile.() [:freeze] = ![:no_freeze] [:validate] = false if [:skip_syntax_check] berksfile.upload(names, .symbolize_keys) end |
#vendor(path = File.join(Dir.pwd, "berks-cookbooks")) ⇒ Object
393 394 395 396 |
# File 'lib/berkshelf/cli.rb', line 393 def vendor(path = File.join(Dir.pwd, "berks-cookbooks")) berksfile = Berkshelf::Berksfile.() berksfile.vendor(path) end |
#verify ⇒ Object
402 403 404 405 406 |
# File 'lib/berkshelf/cli.rb', line 402 def verify berksfile = Berksfile.() berksfile.verify Berkshelf.formatter.msg "Verified." end |