Class: ChefDK::Command::DescribeCookbook

Inherits:
Base
  • Object
show all
Defined in:
lib/chef-dk/command/describe_cookbook.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#check_license_acceptance, #needs_help?, #needs_version?, #run_with_default_options

Methods included from Helpers

#chefdk_home, #err, #git_bin_dir, #git_windows_bin_dir, #msg, #omnibus_apps_dir, #omnibus_bin_dir, #omnibus_chefdk_location, #omnibus_embedded_bin_dir, #omnibus_env, #omnibus_install?, #omnibus_root, #stderr, #stdout, #system_command, #usr_bin_path, #usr_bin_prefix

Constructor Details

#initialize(*args) ⇒ DescribeCookbook

Returns a new instance of DescribeCookbook.



57
58
59
60
61
# File 'lib/chef-dk/command/describe_cookbook.rb', line 57

def initialize(*args)
  super
  @cookbook_path = nil
  @ui = UI.new
end

Instance Attribute Details

#cookbook_pathObject (readonly)

Returns the value of attribute cookbook_path.



54
55
56
# File 'lib/chef-dk/command/describe_cookbook.rb', line 54

def cookbook_path
  @cookbook_path
end

#uiObject (readonly)

Returns the value of attribute ui.



55
56
57
# File 'lib/chef-dk/command/describe_cookbook.rb', line 55

def ui
  @ui
end

Instance Method Details

#apply_params!(params) ⇒ Object



86
87
88
89
90
91
92
93
94
95
# 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_pathObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# 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 = []) ⇒ Object



63
64
65
66
67
68
# 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