Class: ChefDK::Command::GeneratorCommands::Cookbook
- Inherits:
-
Base
- Object
- Base
- Base
- ChefDK::Command::GeneratorCommands::Cookbook
show all
- Defined in:
- lib/chef-dk/command/generator_commands/cookbook.rb
Overview
## CookbookFile chef generate cookbook path/to/basename –generator-cookbook=path/to/generator
Generates a basic cookbook directory structure. Most file types are omitted, the user is expected to add additional files as needed using the relevant generators.
Instance Attribute Summary collapse
Attributes inherited from Base
#params
Instance Method Summary
collapse
Methods inherited from Base
#chef_runner, #generator_cookbook_name, #generator_cookbook_path, #have_git?
#chef_config, #chefdk_config, #config_loader
Methods inherited from Base
#needs_help?, #needs_version?, #run_with_default_options
Methods included from Helpers
#chefdk_home, #err, #msg, #omnibus_apps_dir, #omnibus_bin_dir, #omnibus_chefdk_location, #omnibus_embedded_bin_dir, #omnibus_install?, #omnibus_root, #stderr, #stdout, #system_command, #usr_bin_path, #usr_bin_prefix
Constructor Details
#initialize(params) ⇒ Cookbook
Returns a new instance of Cookbook.
40
41
42
43
44
|
# File 'lib/chef-dk/command/generator_commands/cookbook.rb', line 40
def initialize(params)
@params_valid = true
@cookbook_name = nil
super
end
|
Instance Attribute Details
#cookbook_name_or_path ⇒ Object
Returns the value of attribute cookbook_name_or_path.
36
37
38
|
# File 'lib/chef-dk/command/generator_commands/cookbook.rb', line 36
def cookbook_name_or_path
@cookbook_name_or_path
end
|
#errors ⇒ Object
Returns the value of attribute errors.
34
35
36
|
# File 'lib/chef-dk/command/generator_commands/cookbook.rb', line 34
def errors
@errors
end
|
Instance Method Details
#cookbook_full_path ⇒ Object
95
96
97
|
# File 'lib/chef-dk/command/generator_commands/cookbook.rb', line 95
def cookbook_full_path
File.expand_path(cookbook_name_or_path, Dir.pwd)
end
|
#cookbook_name ⇒ Object
87
88
89
|
# File 'lib/chef-dk/command/generator_commands/cookbook.rb', line 87
def cookbook_name
File.basename(cookbook_full_path)
end
|
#cookbook_path_in_git_repo? ⇒ Boolean
109
110
111
112
113
114
|
# File 'lib/chef-dk/command/generator_commands/cookbook.rb', line 109
def cookbook_path_in_git_repo?
Pathname.new(cookbook_full_path).ascend do |dir|
return true if File.directory?(File.join(dir.to_s, ".git"))
end
false
end
|
#cookbook_root ⇒ Object
91
92
93
|
# File 'lib/chef-dk/command/generator_commands/cookbook.rb', line 91
def cookbook_root
File.dirname(cookbook_full_path)
end
|
#params_valid? ⇒ Boolean
105
106
107
|
# File 'lib/chef-dk/command/generator_commands/cookbook.rb', line 105
def params_valid?
@params_valid
end
|
#policy_name ⇒ Object
71
72
73
|
# File 'lib/chef-dk/command/generator_commands/cookbook.rb', line 71
def policy_name
cookbook_name
end
|
#policy_run_list ⇒ Object
75
76
77
|
# File 'lib/chef-dk/command/generator_commands/cookbook.rb', line 75
def policy_run_list
"#{cookbook_name}::#{recipe_name}"
end
|
#read_and_validate_params ⇒ Object
99
100
101
102
103
|
# File 'lib/chef-dk/command/generator_commands/cookbook.rb', line 99
def read_and_validate_params
arguments = parse_options(params)
@cookbook_name_or_path = arguments[0]
@params_valid = false unless @cookbook_name_or_path
end
|
#recipe ⇒ Object
79
80
81
|
# File 'lib/chef-dk/command/generator_commands/cookbook.rb', line 79
def recipe
"cookbook"
end
|
#recipe_name ⇒ Object
83
84
85
|
# File 'lib/chef-dk/command/generator_commands/cookbook.rb', line 83
def recipe_name
"default"
end
|
#run ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/chef-dk/command/generator_commands/cookbook.rb', line 46
def run
read_and_validate_params
if params_valid?
setup_context
chef_runner.converge
else
err(opt_parser)
1
end
rescue ChefDK::ChefRunnerError => e
err("ERROR: #{e}")
1
end
|