Class: ChefDK::Command::GeneratorCommands::Cookbook
- Inherits:
-
Base
- Object
- Base
- Base
- ChefDK::Command::GeneratorCommands::Cookbook
show all
- Defined in:
- lib/chef-dk/command/generator_commands.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_context, #generator_cookbook_path, #have_git?
Methods inherited from Base
#needs_help?, #needs_version?, #run_with_default_options
Methods included from Helpers
#err, #msg, #omnibus_apps_dir, #omnibus_bin_dir, #omnibus_embedded_bin_dir, #omnibus_root, #stderr, #stdout, #system_command
Constructor Details
#initialize(params) ⇒ Cookbook
Returns a new instance of Cookbook.
197
198
199
200
201
|
# File 'lib/chef-dk/command/generator_commands.rb', line 197
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.
193
194
195
|
# File 'lib/chef-dk/command/generator_commands.rb', line 193
def cookbook_name_or_path
@cookbook_name_or_path
end
|
#errors ⇒ Object
Returns the value of attribute errors.
191
192
193
|
# File 'lib/chef-dk/command/generator_commands.rb', line 191
def errors
@errors
end
|
Instance Method Details
#cookbook_full_path ⇒ Object
233
234
235
|
# File 'lib/chef-dk/command/generator_commands.rb', line 233
def cookbook_full_path
File.expand_path(cookbook_name_or_path, Dir.pwd)
end
|
#cookbook_name ⇒ Object
225
226
227
|
# File 'lib/chef-dk/command/generator_commands.rb', line 225
def cookbook_name
File.basename(cookbook_full_path)
end
|
#cookbook_path_in_git_repo? ⇒ Boolean
247
248
249
250
251
252
|
# File 'lib/chef-dk/command/generator_commands.rb', line 247
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
229
230
231
|
# File 'lib/chef-dk/command/generator_commands.rb', line 229
def cookbook_root
File.dirname(cookbook_full_path)
end
|
#params_valid? ⇒ Boolean
243
244
245
|
# File 'lib/chef-dk/command/generator_commands.rb', line 243
def params_valid?
@params_valid
end
|
#read_and_validate_params ⇒ Object
237
238
239
240
241
|
# File 'lib/chef-dk/command/generator_commands.rb', line 237
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
221
222
223
|
# File 'lib/chef-dk/command/generator_commands.rb', line 221
def recipe
"cookbook"
end
|
#run ⇒ Object
203
204
205
206
207
208
209
210
211
212
|
# File 'lib/chef-dk/command/generator_commands.rb', line 203
def run
read_and_validate_params
if params_valid?
setup_context
chef_runner.converge
else
msg(banner)
1
end
end
|
#setup_context ⇒ Object
214
215
216
217
218
219
|
# File 'lib/chef-dk/command/generator_commands.rb', line 214
def setup_context
super
generator_context.skip_git_init = cookbook_path_in_git_repo?
generator_context.cookbook_root = cookbook_root
generator_context.cookbook_name = cookbook_name
end
|