chef-dk 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CONTRIBUTING.md +192 -0
- data/LICENSE +201 -0
- data/README.md +198 -0
- data/Rakefile +18 -0
- data/bin/chef +25 -0
- data/lib/chef-dk.rb +19 -0
- data/lib/chef-dk/builtin_commands.rb +31 -0
- data/lib/chef-dk/chef_runner.rb +83 -0
- data/lib/chef-dk/cli.rb +135 -0
- data/lib/chef-dk/command/base.rb +71 -0
- data/lib/chef-dk/command/exec.rb +33 -0
- data/lib/chef-dk/command/gem.rb +47 -0
- data/lib/chef-dk/command/generate.rb +97 -0
- data/lib/chef-dk/command/generator_commands.rb +417 -0
- data/lib/chef-dk/command/shell_init.rb +80 -0
- data/lib/chef-dk/command/verify.rb +226 -0
- data/lib/chef-dk/commands_map.rb +115 -0
- data/lib/chef-dk/component_test.rb +142 -0
- data/lib/chef-dk/cookbook_metadata.rb +36 -0
- data/lib/chef-dk/cookbook_omnifetch.rb +29 -0
- data/lib/chef-dk/cookbook_profiler/git.rb +95 -0
- data/lib/chef-dk/cookbook_profiler/identifiers.rb +79 -0
- data/lib/chef-dk/cookbook_profiler/null_scm.rb +32 -0
- data/lib/chef-dk/exceptions.rb +46 -0
- data/lib/chef-dk/generator.rb +70 -0
- data/lib/chef-dk/helpers.rb +95 -0
- data/lib/chef-dk/policyfile/chef_server_cookbook_source.rb +46 -0
- data/lib/chef-dk/policyfile/community_cookbook_source.rb +84 -0
- data/lib/chef-dk/policyfile/cookbook_sources.rb +20 -0
- data/lib/chef-dk/policyfile/cookbook_spec.rb +96 -0
- data/lib/chef-dk/policyfile/dsl.rb +148 -0
- data/lib/chef-dk/policyfile/null_cookbook_source.rb +37 -0
- data/lib/chef-dk/policyfile_compiler.rb +217 -0
- data/lib/chef-dk/policyfile_lock.rb +243 -0
- data/lib/chef-dk/shell_out.rb +36 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/Berksfile +3 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/chefignore +96 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/converge_spec.rb +9 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/gitignore +16 -0
- data/lib/chef-dk/skeletons/code_generator/files/default/spec_helper.rb +8 -0
- data/lib/chef-dk/skeletons/code_generator/metadata.rb +8 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/app.rb +65 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/attribute.rb +12 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/cookbook.rb +50 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/cookbook_file.rb +24 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/lwrp.rb +23 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/recipe.rb +9 -0
- data/lib/chef-dk/skeletons/code_generator/recipes/template.rb +32 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/README.md.erb +4 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/attribute.rb.erb +0 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/cookbook_file.erb +0 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/default_recipe.rb.erb +8 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/kitchen.yml.erb +16 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/metadata.rb.erb +8 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/provider.rb.erb +0 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/recipe.rb.erb +0 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/resource.rb.erb +0 -0
- data/lib/chef-dk/skeletons/code_generator/templates/default/template.erb +0 -0
- data/lib/chef-dk/version.rb +20 -0
- data/spec/shared/setup_git_cookbooks.rb +53 -0
- data/spec/spec_helper.rb +32 -0
- data/spec/test_helpers.rb +59 -0
- data/spec/unit/chef_runner_spec.rb +70 -0
- data/spec/unit/cli_spec.rb +151 -0
- data/spec/unit/command/base_spec.rb +88 -0
- data/spec/unit/command/exec_spec.rb +123 -0
- data/spec/unit/command/generate_spec.rb +102 -0
- data/spec/unit/command/generator_commands_spec.rb +504 -0
- data/spec/unit/command/shell_init_spec.rb +109 -0
- data/spec/unit/command/verify_spec.rb +311 -0
- data/spec/unit/commands_map_spec.rb +57 -0
- data/spec/unit/component_test_spec.rb +126 -0
- data/spec/unit/cookbook_metadata_spec.rb +62 -0
- data/spec/unit/cookbook_profiler/git_spec.rb +127 -0
- data/spec/unit/cookbook_profiler/identifiers_spec.rb +79 -0
- data/spec/unit/fixtures/chef-runner-cookbooks/test_cookbook/recipes/recipe_one.rb +9 -0
- data/spec/unit/fixtures/chef-runner-cookbooks/test_cookbook/recipes/recipe_two.rb +9 -0
- data/spec/unit/fixtures/command/cli_test_command.rb +26 -0
- data/spec/unit/fixtures/command/explicit_path_example.rb +7 -0
- data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/.kitchen.yml +16 -0
- data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/Berksfile +3 -0
- data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/README.md +4 -0
- data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/chefignore +96 -0
- data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/metadata.rb +8 -0
- data/spec/unit/fixtures/cookbook_cache/baz-f59ee7a5bca6a4e606b67f7f856b768d847c39bb/recipes/default.rb +8 -0
- data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/.kitchen.yml +16 -0
- data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/Berksfile +3 -0
- data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/README.md +4 -0
- data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/chefignore +96 -0
- data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/metadata.rb +8 -0
- data/spec/unit/fixtures/cookbook_cache/dep_of_bar-1.2.3/recipes/default.rb +8 -0
- data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/.kitchen.yml +16 -0
- data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/Berksfile +3 -0
- data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/README.md +4 -0
- data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/chefignore +96 -0
- data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/metadata.rb +8 -0
- data/spec/unit/fixtures/cookbook_cache/foo-1.0.0/recipes/default.rb +8 -0
- data/spec/unit/fixtures/cookbooks_api/pruned_small_universe.json +1322 -0
- data/spec/unit/fixtures/cookbooks_api/small_universe.json +2987 -0
- data/spec/unit/fixtures/cookbooks_api/universe.json +1 -0
- data/spec/unit/fixtures/cookbooks_api/update_fixtures.rb +36 -0
- data/spec/unit/fixtures/dev_cookbooks/README.md +16 -0
- data/spec/unit/fixtures/dev_cookbooks/bar-cookbook.gitbundle +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/missing_apps/bin/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/missing_apps/embedded/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/missing_apps/embedded/bin/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/missing_component/bin/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/missing_component/embedded/apps/berkshelf/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/missing_component/embedded/apps/test-kitchen/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/missing_component/embedded/bin/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/valid/bin/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/berkshelf/integration_test +2 -0
- data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/berkshelf/verify_me +5 -0
- data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/chef-dk/.keep +0 -0
- data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/chef/verify_me +3 -0
- data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/apps/test-kitchen/verify_me +2 -0
- data/spec/unit/fixtures/eg_omnibus_dir/valid/embedded/bin/.keep +0 -0
- data/spec/unit/fixtures/example_app/Policyfile.rb +0 -0
- data/spec/unit/fixtures/example_cookbook/.gitignore +17 -0
- data/spec/unit/fixtures/example_cookbook/.kitchen.yml +16 -0
- data/spec/unit/fixtures/example_cookbook/Berksfile +3 -0
- data/spec/unit/fixtures/example_cookbook/README.md +4 -0
- data/spec/unit/fixtures/example_cookbook/chefignore +96 -0
- data/spec/unit/fixtures/example_cookbook/metadata.rb +8 -0
- data/spec/unit/fixtures/example_cookbook/recipes/default.rb +8 -0
- data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/.kitchen.yml +16 -0
- data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/Berksfile +3 -0
- data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/README.md +4 -0
- data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/chefignore +96 -0
- data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/metadata.rb +8 -0
- data/spec/unit/fixtures/local_path_cookbooks/local-cookbook/recipes/default.rb +8 -0
- data/spec/unit/fixtures/local_path_cookbooks/metadata-missing/README.md +2 -0
- data/spec/unit/policyfile/chef_server_cookbook_source_spec.rb +34 -0
- data/spec/unit/policyfile/community_cookbook_source_spec.rb +51 -0
- data/spec/unit/policyfile/cookbook_spec_spec.rb +200 -0
- data/spec/unit/policyfile/null_cookbook_source_spec.rb +35 -0
- data/spec/unit/policyfile_builder_spec.rb +489 -0
- data/spec/unit/policyfile_demands_spec.rb +484 -0
- data/spec/unit/policyfile_evaluation_spec.rb +284 -0
- data/spec/unit/shell_out_spec.rb +34 -0
- metadata +422 -0
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2014 Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require "bundler/gem_tasks"
|
data/bin/chef
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Copyright:: Copyright (c) 2014 Chef Software Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
# Set a trap for ctrl-C right away so we don't surface interrupt exceptions inside of rubygems or whatever.
|
20
|
+
Kernel.trap(:INT) { print("\n"); exit 1 }
|
21
|
+
|
22
|
+
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")))
|
23
|
+
require 'chef-dk/cli'
|
24
|
+
|
25
|
+
ChefDK::CLI.new(ARGV.clone).run
|
data/lib/chef-dk.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2014 Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
module ChefDK
|
19
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2014 Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
|
19
|
+
ChefDK.commands do |c|
|
20
|
+
c.builtin "exec", :Exec, require_path: "chef-dk/command/exec",
|
21
|
+
desc: "Runs the command in context of the embedded ruby"
|
22
|
+
|
23
|
+
c.builtin "gem", :GemForwarder, require_path: "chef-dk/command/gem",
|
24
|
+
desc: "Runs the `gem` command in context of the embedded ruby"
|
25
|
+
|
26
|
+
c.builtin "generate", :Generate, desc: "Generate a new app, cookbook, or component"
|
27
|
+
|
28
|
+
c.builtin "shell-init", :ShellInit, desc: "Initialize your shell to use ChefDK as your primary ruby"
|
29
|
+
|
30
|
+
c.builtin "verify", :Verify, desc: "Test the embedded ChefDK applications"
|
31
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2014 Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require 'chef'
|
19
|
+
|
20
|
+
module ChefDK
|
21
|
+
# An adapter to chef's APIs to kick off a chef-client run.
|
22
|
+
class ChefRunner
|
23
|
+
|
24
|
+
attr_reader :cookbook_path
|
25
|
+
attr_reader :run_list
|
26
|
+
|
27
|
+
def initialize(cookbook_path, run_list)
|
28
|
+
@cookbook_path = cookbook_path
|
29
|
+
@run_list = run_list
|
30
|
+
@formatter = nil
|
31
|
+
@ohai = nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def converge
|
35
|
+
configure
|
36
|
+
Chef::Runner.new(run_context).converge
|
37
|
+
end
|
38
|
+
|
39
|
+
def run_context
|
40
|
+
@run_context ||= policy.setup_run_context
|
41
|
+
end
|
42
|
+
|
43
|
+
def policy
|
44
|
+
return @policy_builder if @policy_builder
|
45
|
+
|
46
|
+
@policy_builder = Chef::PolicyBuilder::ExpandNodeObject.new("chef-dk", ohai.data, {}, nil, formatter)
|
47
|
+
@policy_builder.load_node
|
48
|
+
@policy_builder.build_node
|
49
|
+
@policy_builder.node.run_list(*run_list)
|
50
|
+
@policy_builder.expand_run_list
|
51
|
+
@policy_builder
|
52
|
+
end
|
53
|
+
|
54
|
+
def formatter
|
55
|
+
@formatter ||= Chef::Formatters.new(:doc, stdout, stderr)
|
56
|
+
end
|
57
|
+
|
58
|
+
def configure
|
59
|
+
Chef::Config.solo = true
|
60
|
+
Chef::Config.cookbook_path = cookbook_path
|
61
|
+
Chef::Config.color = true
|
62
|
+
Chef::Config.diff_disabled = true
|
63
|
+
end
|
64
|
+
|
65
|
+
def ohai
|
66
|
+
return @ohai if @ohai
|
67
|
+
|
68
|
+
@ohai = Ohai::System.new
|
69
|
+
@ohai.all_plugins(["platform", "platform_version"])
|
70
|
+
@ohai
|
71
|
+
end
|
72
|
+
|
73
|
+
def stdout
|
74
|
+
$stdout
|
75
|
+
end
|
76
|
+
|
77
|
+
def stderr
|
78
|
+
$stderr
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
data/lib/chef-dk/cli.rb
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2014 Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require 'mixlib/cli'
|
19
|
+
require 'chef-dk/version'
|
20
|
+
require 'chef-dk/commands_map'
|
21
|
+
require 'chef-dk/builtin_commands'
|
22
|
+
require 'chef-dk/helpers'
|
23
|
+
|
24
|
+
module ChefDK
|
25
|
+
class CLI
|
26
|
+
include Mixlib::CLI
|
27
|
+
include ChefDK::Helpers
|
28
|
+
|
29
|
+
banner(<<-BANNER)
|
30
|
+
Usage:
|
31
|
+
chef -h/--help
|
32
|
+
chef -v/--version
|
33
|
+
chef command [arguments...] [options...]
|
34
|
+
BANNER
|
35
|
+
|
36
|
+
option :version,
|
37
|
+
:short => "-v",
|
38
|
+
:long => "--version",
|
39
|
+
:description => "Show chef version",
|
40
|
+
:boolean => true
|
41
|
+
|
42
|
+
option :help,
|
43
|
+
:short => "-h",
|
44
|
+
:long => "--help",
|
45
|
+
:description => "Show this message",
|
46
|
+
:boolean => true
|
47
|
+
|
48
|
+
attr_reader :argv
|
49
|
+
|
50
|
+
def initialize(argv)
|
51
|
+
@argv = argv
|
52
|
+
super() # mixlib-cli #initialize doesn't allow arguments
|
53
|
+
end
|
54
|
+
|
55
|
+
def run
|
56
|
+
subcommand_name, *subcommand_params = argv
|
57
|
+
|
58
|
+
#
|
59
|
+
# Runs the appropriate subcommand if the given parameters contain any
|
60
|
+
# subcommands.
|
61
|
+
#
|
62
|
+
if subcommand_name.nil? || option?(subcommand_name)
|
63
|
+
handle_options
|
64
|
+
elsif have_command?(subcommand_name)
|
65
|
+
subcommand = instantiate_subcommand(subcommand_name)
|
66
|
+
exit_code = subcommand.run_with_default_options(subcommand_params)
|
67
|
+
exit normalized_exit_code(exit_code)
|
68
|
+
else
|
69
|
+
err "Unknown command `#{subcommand_name}'."
|
70
|
+
show_help
|
71
|
+
exit 1
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# If no subcommand is given, then this class is handling the CLI request.
|
76
|
+
def handle_options
|
77
|
+
parse_options(argv)
|
78
|
+
if config[:version]
|
79
|
+
msg("Chef Development Kit Version: #{ChefDK::VERSION}")
|
80
|
+
else
|
81
|
+
show_help
|
82
|
+
end
|
83
|
+
exit 0
|
84
|
+
end
|
85
|
+
|
86
|
+
def show_help
|
87
|
+
msg(banner)
|
88
|
+
msg("\nAvailable Commands:")
|
89
|
+
|
90
|
+
justify_length = subcommands.map(&:length).max + 2
|
91
|
+
subcommand_specs.each do |name, spec|
|
92
|
+
msg(" #{"#{name}".ljust(justify_length)}#{spec.description}")
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def exit(n)
|
97
|
+
Kernel.exit(n)
|
98
|
+
end
|
99
|
+
|
100
|
+
def commands_map
|
101
|
+
ChefDK.commands_map
|
102
|
+
end
|
103
|
+
|
104
|
+
def have_command?(name)
|
105
|
+
commands_map.have_command?(name)
|
106
|
+
end
|
107
|
+
|
108
|
+
def subcommands
|
109
|
+
commands_map.command_names
|
110
|
+
end
|
111
|
+
|
112
|
+
def subcommand_specs
|
113
|
+
commands_map.command_specs
|
114
|
+
end
|
115
|
+
|
116
|
+
def option?(param)
|
117
|
+
param =~ /^-/
|
118
|
+
end
|
119
|
+
|
120
|
+
def instantiate_subcommand(name)
|
121
|
+
commands_map.instantiate(name)
|
122
|
+
end
|
123
|
+
|
124
|
+
private
|
125
|
+
|
126
|
+
def normalized_exit_code(maybe_integer)
|
127
|
+
if maybe_integer.kind_of?(Integer) and (0..255).include?(maybe_integer)
|
128
|
+
maybe_integer
|
129
|
+
else
|
130
|
+
0
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2014 Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require 'mixlib/cli'
|
19
|
+
require 'chef-dk/helpers'
|
20
|
+
require 'chef-dk/version'
|
21
|
+
|
22
|
+
module ChefDK
|
23
|
+
module Command
|
24
|
+
class Base
|
25
|
+
include Mixlib::CLI
|
26
|
+
include ChefDK::Helpers
|
27
|
+
|
28
|
+
option :help,
|
29
|
+
:short => "-h",
|
30
|
+
:long => "--help",
|
31
|
+
:description => "Show this message",
|
32
|
+
:boolean => true
|
33
|
+
|
34
|
+
option :version,
|
35
|
+
:short => "-v",
|
36
|
+
:long => "--version",
|
37
|
+
:description => "Show chef version",
|
38
|
+
:boolean => true
|
39
|
+
|
40
|
+
def initialize
|
41
|
+
super
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# optparser overwrites -h / --help options with its own.
|
46
|
+
# In order to control this behavior, make sure the default options are
|
47
|
+
# handled here.
|
48
|
+
#
|
49
|
+
def run_with_default_options(params = [ ])
|
50
|
+
if needs_help?(params)
|
51
|
+
msg(opt_parser.to_s)
|
52
|
+
0
|
53
|
+
elsif needs_version?(params)
|
54
|
+
msg("Chef Development Kit Version: #{ChefDK::VERSION}")
|
55
|
+
0
|
56
|
+
else
|
57
|
+
run(params)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def needs_help?(params)
|
62
|
+
params.include?("-h") || params.include?("--help")
|
63
|
+
end
|
64
|
+
|
65
|
+
def needs_version?(params)
|
66
|
+
params.include?("-v") || params.include?("--version")
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2014 Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require 'chef-dk/command/base'
|
19
|
+
require 'mixlib/shellout'
|
20
|
+
|
21
|
+
module ChefDK
|
22
|
+
module Command
|
23
|
+
class Exec < ChefDK::Command::Base
|
24
|
+
banner "Usage: chef exec SYSTEM_COMMAND"
|
25
|
+
|
26
|
+
def run(params)
|
27
|
+
exec omnibus_env, *params
|
28
|
+
raise "Exec failed without an exception, your ruby is buggy" # should never get here
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2014 Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require 'chef-dk/command/base'
|
19
|
+
require 'rubygems'
|
20
|
+
require 'rubygems/gem_runner'
|
21
|
+
require 'rubygems/exceptions'
|
22
|
+
require 'pp'
|
23
|
+
|
24
|
+
module ChefDK
|
25
|
+
module Command
|
26
|
+
|
27
|
+
# Forwards all commands to rubygems.
|
28
|
+
class GemForwarder < ChefDK::Command::Base
|
29
|
+
banner "Usage: chef gem GEM_COMMANDS_AND_OPTIONS"
|
30
|
+
|
31
|
+
def run(params)
|
32
|
+
retval = Gem::GemRunner.new.run( params.clone )
|
33
|
+
retval.nil? ? true : retval
|
34
|
+
rescue Gem::SystemExitException => e
|
35
|
+
exit( e.exit_code )
|
36
|
+
end
|
37
|
+
|
38
|
+
# Lazy solution: By automatically returning false, we force ChefDK::Base to
|
39
|
+
# call this class' run method, so that Gem::GemRunner can handle the -v flag
|
40
|
+
# appropriately (showing the gem version, or installing a specific version
|
41
|
+
# of a gem).
|
42
|
+
def needs_version?(params)
|
43
|
+
false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|