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_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.
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
76
77
78
|
# File 'lib/chef-dk/command/generator_commands/cookbook.rb', line 76
def cookbook_full_path
File.expand_path(cookbook_name_or_path, Dir.pwd)
end
|
#cookbook_name ⇒ Object
68
69
70
|
# File 'lib/chef-dk/command/generator_commands/cookbook.rb', line 68
def cookbook_name
File.basename(cookbook_full_path)
end
|
#cookbook_path_in_git_repo? ⇒ Boolean
90
91
92
93
94
95
|
# File 'lib/chef-dk/command/generator_commands/cookbook.rb', line 90
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
72
73
74
|
# File 'lib/chef-dk/command/generator_commands/cookbook.rb', line 72
def cookbook_root
File.dirname(cookbook_full_path)
end
|
#params_valid? ⇒ Boolean
86
87
88
|
# File 'lib/chef-dk/command/generator_commands/cookbook.rb', line 86
def params_valid?
@params_valid
end
|
#read_and_validate_params ⇒ Object
80
81
82
83
84
|
# File 'lib/chef-dk/command/generator_commands/cookbook.rb', line 80
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
64
65
66
|
# File 'lib/chef-dk/command/generator_commands/cookbook.rb', line 64
def recipe
"cookbook"
end
|
#run ⇒ Object
46
47
48
49
50
51
52
53
54
55
|
# 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
msg(banner)
1
end
end
|
#setup_context ⇒ Object
57
58
59
60
61
62
|
# File 'lib/chef-dk/command/generator_commands/cookbook.rb', line 57
def setup_context
super
Generator.add_attr_to_context(:skip_git_init, cookbook_path_in_git_repo?)
Generator.add_attr_to_context(:cookbook_root, cookbook_root)
Generator.add_attr_to_context(:cookbook_name, cookbook_name)
end
|