Class: ChefDK::Command::GeneratorCommands::BuildCookbook
- Inherits:
-
Base
- Object
- Base
- Base
- ChefDK::Command::GeneratorCommands::BuildCookbook
show all
- Defined in:
- lib/chef-dk/command/generator_commands/build_cookbook.rb
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, #default_chef_server_http_client, #generator_config, #knife_config, #reset_config!
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
Returns a new instance of BuildCookbook.
40
41
42
43
44
|
# File 'lib/chef-dk/command/generator_commands/build_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.
31
32
33
|
# File 'lib/chef-dk/command/generator_commands/build_cookbook.rb', line 31
def cookbook_name_or_path
@cookbook_name_or_path
end
|
#errors ⇒ Object
Returns the value of attribute errors.
29
30
31
|
# File 'lib/chef-dk/command/generator_commands/build_cookbook.rb', line 29
def errors
@errors
end
|
Instance Method Details
#build_cookbook_parent_is_cookbook? ⇒ Boolean
79
80
81
82
83
84
|
# File 'lib/chef-dk/command/generator_commands/build_cookbook.rb', line 79
def build_cookbook_parent_is_cookbook?
metadata_json_path = File.join(workflow_project_dir, "metadata.json")
metadata_rb_path = File.join(workflow_project_dir, "metadata.rb")
File.exist?(metadata_json_path) || File.exist?(metadata_rb_path)
end
|
#params_valid? ⇒ Boolean
119
120
121
|
# File 'lib/chef-dk/command/generator_commands/build_cookbook.rb', line 119
def params_valid?
@params_valid
end
|
#pipeline ⇒ Object
71
72
73
|
# File 'lib/chef-dk/command/generator_commands/build_cookbook.rb', line 71
def pipeline
config[:pipeline]
end
|
#read_and_validate_params ⇒ Object
111
112
113
114
115
116
117
|
# File 'lib/chef-dk/command/generator_commands/build_cookbook.rb', line 111
def read_and_validate_params
arguments = parse_options(params)
@cookbook_name_or_path = arguments[0]
unless @cookbook_name_or_path
@params_valid = false
end
end
|
#recipe ⇒ Object
75
76
77
|
# File 'lib/chef-dk/command/generator_commands/build_cookbook.rb', line 75
def recipe
"build_cookbook"
end
|
#run ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/chef-dk/command/generator_commands/build_cookbook.rb', line 46
def run
read_and_validate_params
if params_valid?
setup_context
chef_runner.converge
0
else
err(opt_parser)
1
end
rescue ChefDK::ChefRunnerError => e
err("ERROR: #{e}")
1
end
|
#workflow_project_dir ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/chef-dk/command/generator_commands/build_cookbook.rb', line 86
def workflow_project_dir
project_dir = File.expand_path(cookbook_name_or_path, Dir.pwd)
Pathname.new(project_dir).ascend do |dir|
if File.basename(dir) == ".delivery"
project_dir = File.dirname(dir)
end
end
project_dir
end
|
#workflow_project_git_initialized? ⇒ Boolean
107
108
109
|
# File 'lib/chef-dk/command/generator_commands/build_cookbook.rb', line 107
def workflow_project_git_initialized?
File.exist?(File.join(workflow_project_dir, ".git"))
end
|