Class: Berkshelf::Cli
- Defined in:
- lib/berkshelf/cli.rb,
lib/berkshelf/commands/shelf.rb
Defined Under Namespace
Classes: Runner
Class Method Summary collapse
Instance Method Summary collapse
- #apply(environment_name) ⇒ Object
- #contingent(name) ⇒ Object
- #info(name) ⇒ 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.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# 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 = .dup # unfreeze frozen options Hash from Thor end |
Class Method Details
.dispatch(meth, given_args, given_opts, config) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# 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 |
Instance Method Details
#apply(environment_name) ⇒ Object
213 214 215 216 217 218 219 220 221 222 |
# File 'lib/berkshelf/cli.rb', line 213 def apply(environment_name) unless File.exist?([:lockfile]) raise LockfileNotFound, "No lockfile found at #{[:lockfile]}" end lockfile = Lockfile.from_file([:lockfile]) = Hash[].each_with_object({}) { |(k, v), m| m[k.to_sym] = v } lockfile.apply(environment_name, ) end |
#contingent(name) ⇒ Object
315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/berkshelf/cli.rb', line 315 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 |
#info(name) ⇒ Object
289 290 291 292 293 |
# File 'lib/berkshelf/cli.rb', line 289 def info(name) berksfile = Berksfile.() cookbook = berksfile.retrieve_locked(name) Berkshelf.formatter.info(cookbook) end |
#install ⇒ Object
129 130 131 132 |
# File 'lib/berkshelf/cli.rb', line 129 def install berksfile = Berksfile.() berksfile.install end |
#list ⇒ Object
277 278 279 280 |
# File 'lib/berkshelf/cli.rb', line 277 def list berksfile = Berksfile.() Berkshelf.formatter.list(berksfile.list) end |
#outdated(*names) ⇒ Object
244 245 246 247 248 |
# File 'lib/berkshelf/cli.rb', line 244 def outdated(*names) berksfile = Berksfile.() outdated = berksfile.outdated(*names, include_non_satisfying: [:all]) Berkshelf.formatter.outdated(outdated) end |
#package(path = nil) ⇒ Object
344 345 346 347 348 349 350 351 352 353 |
# 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.(path) end berksfile = Berksfile.() berksfile.package(path) end |
#search(name) ⇒ Object
256 257 258 259 260 |
# File 'lib/berkshelf/cli.rb', line 256 def search(name) source = Source.new(nil, [:source]) cookbooks = source.search(name) Berkshelf.formatter.search(cookbooks) end |
#show(name) ⇒ Object
302 303 304 305 306 |
# File 'lib/berkshelf/cli.rb', line 302 def show(name) berksfile = Berksfile.() cookbook = berksfile.retrieve_locked(name) Berkshelf.formatter.show(cookbook) end |
#update(*cookbook_names) ⇒ Object
149 150 151 152 |
# File 'lib/berkshelf/cli.rb', line 149 def update(*cookbook_names) berksfile = Berksfile.() berksfile.update(*cookbook_names) end |
#upload(*names) ⇒ Object
190 191 192 193 194 195 196 |
# File 'lib/berkshelf/cli.rb', line 190 def upload(*names) berksfile = Berksfile.() [:freeze] = ![:no_freeze] [:validate] = false if [:skip_syntax_check] berksfile.upload(names, .each_with_object({}) { |(k, v), m| m[k.to_sym] = v }) end |
#vendor(path = File.join(Dir.pwd, "berks-cookbooks")) ⇒ Object
374 375 376 377 |
# File 'lib/berkshelf/cli.rb', line 374 def vendor(path = File.join(Dir.pwd, "berks-cookbooks")) berksfile = Berkshelf::Berksfile.() berksfile.vendor(path) end |
#verify ⇒ Object
383 384 385 386 387 |
# File 'lib/berkshelf/cli.rb', line 383 def verify berksfile = Berksfile.() berksfile.verify Berkshelf.formatter.msg "Verified." end |