class ChefDK::Command::DescribeCookbook

Attributes

cookbook_path[R]
ui[R]

Public Class Methods

new(*args) click to toggle source
Calls superclass method ChefDK::Command::Base::new
# File lib/chef-dk/command/describe_cookbook.rb, line 57
def initialize(*args)
  super
  @cookbook_path = nil
  @ui = UI.new
end

Public Instance Methods

apply_params!(params) click to toggle source
# File lib/chef-dk/command/describe_cookbook.rb, line 86
def apply_params!(params)
  remaining_args = parse_options(params)
  if remaining_args.size != 1
    ui.err(opt_parser)
    return false
  else
    @cookbook_path = File.expand_path(remaining_args.first)
    true
  end
end
check_cookbook_path() click to toggle source
# File lib/chef-dk/command/describe_cookbook.rb, line 70
def check_cookbook_path
  unless File.exist?(cookbook_path)
    ui.err("Given cookbook path '#{cookbook_path}' does not exist or is not readable")
    return false
  end

  mdrb_path = File.join(cookbook_path, "metadata.rb")
  mdjson_path = File.join(cookbook_path, "metadata.json")

  unless File.exist?(mdrb_path) || File.exist?(mdjson_path)
    ui.err("Given cookbook path '#{cookbook_path}' does not appear to be a cookbook, it does not contain a metadata.rb or metadata.json")
    return false
  end
  true
end
run(params = []) click to toggle source
# File lib/chef-dk/command/describe_cookbook.rb, line 63
def run(params = [])
  return 1 unless apply_params!(params)
  return 1 unless check_cookbook_path

  IdDumper.new(ui, cookbook_path).run
end