Skip to content

Commit 9f15f3d

Browse files
Nuo YanSeth Falcon
authored andcommitted
knife node show foobar -E shows the environment a node is in.
1 parent 23e18e2 commit 9f15f3d

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

chef/lib/chef/knife.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def self.list_commands(preferred_category=nil)
121121
def self.run(args, options={})
122122
load_commands
123123
subcommand_class = subcommand_class_from(args)
124-
subcommand_class.options.merge!(options)
124+
subcommand_class.options = options.merge!(subcommand_class.options)
125125
instance = subcommand_class.new(args)
126126
instance.configure_chef
127127
instance.run
@@ -324,6 +324,13 @@ def format_for_display(item)
324324
elsif config[:run_list]
325325
data = data.run_list.run_list
326326
{ "run_list" => data }
327+
elsif config[:environment]
328+
if data.class == Chef::Node
329+
{"chef_environment" => data.chef_environment}
330+
else
331+
# this is a place holder for now. Feel free to modify (i.e. add other cases). [nuo]
332+
data
333+
end
327334
elsif config[:id_only]
328335
data.respond_to?(:name) ? data.name : data["id"]
329336
else

chef/lib/chef/knife/node_show.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ class NodeShow < Knife
3535
:short => "-r",
3636
:long => "--run-list",
3737
:description => "Show only the run list"
38+
39+
option :environment,
40+
:short => "-E",
41+
:long => "--environment",
42+
:description => "Show only the Chef environment"
3843

3944
def run
4045
@node_name = @name_args[0]

chef/spec/unit/knife/node_show_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
@knife = Chef::Knife::NodeShow.new
2525
@knife.config = {
2626
:attribute => nil,
27-
:run_list => nil
27+
:run_list => nil,
28+
:environment => nil
2829
}
2930
@knife.name_args = [ "adam" ]
3031
@knife.stub!(:output).and_return(true)

0 commit comments

Comments
 (0)