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
222 223 224 225 226 227 228 229 230 231 |
# File 'lib/berkshelf/cli.rb', line 222 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
330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/berkshelf/cli.rb', line 330 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
426 427 428 429 430 431 432 |
# File 'lib/berkshelf/cli.rb', line 426 def cookbook(name, path = nil) 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
304 305 306 307 308 |
# File 'lib/berkshelf/cli.rb', line 304 def info(name) berksfile = Berksfile.() cookbook = berksfile.retrieve_locked(name) Berkshelf.formatter.info(cookbook) end |
#init(path = '.') ⇒ Object
267 268 269 270 271 272 273 274 |
# File 'lib/berkshelf/cli.rb', line 267 def init(path = '.') 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
292 293 294 295 |
# File 'lib/berkshelf/cli.rb', line 292 def list berksfile = Berksfile.() Berkshelf.formatter.list(berksfile.list) end |
#outdated(*names) ⇒ Object
248 249 250 251 252 |
# File 'lib/berkshelf/cli.rb', line 248 def outdated(*names) berksfile = Berksfile.() outdated = berksfile.outdated(*names) Berkshelf.formatter.outdated(outdated) end |
#package(path = nil) ⇒ Object
359 360 361 362 363 364 365 366 367 368 |
# File 'lib/berkshelf/cli.rb', line 359 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
260 261 262 263 264 |
# File 'lib/berkshelf/cli.rb', line 260 def search(name) source = Source.new([:source]) cookbooks = source.search(name) Berkshelf.formatter.search(cookbooks) end |
#show(name) ⇒ Object
317 318 319 320 321 |
# File 'lib/berkshelf/cli.rb', line 317 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
385 386 387 388 |
# File 'lib/berkshelf/cli.rb', line 385 def vendor(path = File.join(Dir.pwd, "berks-cookbooks")) berksfile = Berkshelf::Berksfile.() berksfile.vendor(path) end |
#verify ⇒ Object
394 395 396 397 398 |
# File 'lib/berkshelf/cli.rb', line 394 def verify berksfile = Berksfile.() berksfile.verify Berkshelf.formatter.msg "Verified." end |