diff options
-rw-r--r-- | lib/chef/knife/client_show.rb | 7 | ||||
-rw-r--r-- | lib/chef/knife/core/generic_presenter.rb | 16 | ||||
-rw-r--r-- | lib/chef/knife/environment_show.rb | 9 | ||||
-rw-r--r-- | lib/chef/knife/node_show.rb | 8 | ||||
-rw-r--r-- | lib/chef/knife/role_show.rb | 6 | ||||
-rw-r--r-- | lib/chef/knife/search.rb | 7 | ||||
-rw-r--r-- | lib/chef/knife/user_show.rb | 7 | ||||
-rw-r--r-- | spec/unit/knife/core/ui_spec.rb | 6 |
8 files changed, 33 insertions, 33 deletions
diff --git a/lib/chef/knife/client_show.rb b/lib/chef/knife/client_show.rb index 5c2ffb4183..be6ab75b6a 100644 --- a/lib/chef/knife/client_show.rb +++ b/lib/chef/knife/client_show.rb @@ -22,6 +22,8 @@ class Chef class Knife class ClientShow < Knife + include Knife::Core::MultiAttributeRetrunOption + deps do require 'chef/api_client' require 'chef/json_compat' @@ -29,11 +31,6 @@ class Chef banner "knife client show CLIENT (options)" - option :attribute, - :short => "-a ATTR", - :long => "--attribute ATTR", - :description => "Show only one attribute" - def run @client_name = @name_args[0] diff --git a/lib/chef/knife/core/generic_presenter.rb b/lib/chef/knife/core/generic_presenter.rb index 0866f10147..518252c7b8 100644 --- a/lib/chef/knife/core/generic_presenter.rb +++ b/lib/chef/knife/core/generic_presenter.rb @@ -22,6 +22,22 @@ class Chef class Knife module Core + # Allows includer knife commands to return multiple attribute: + # e.g knife node show NAME -a ATTR1 -a ATTR2 + module MultiAttributeRetrunOption + # :nodoc: + def self.included(includer) + includer.class_eval do + @attrs_to_show = [] + option :attribute, + :short => "-a ATTR1 [-a ATTR2]", + :long => "--attribute ATTR1 [--attribute ATTR2] ", + :proc => lambda {|val| @attrs_to_show << val}, + :description => "Show one or more attributes" + end + end + end + #==Chef::Knife::Core::GenericPresenter # The base presenter class for displaying structured data in knife commands. # This is not an abstract base class, and it is suitable for displaying diff --git a/lib/chef/knife/environment_show.rb b/lib/chef/knife/environment_show.rb index a2b1636f47..2af5668990 100644 --- a/lib/chef/knife/environment_show.rb +++ b/lib/chef/knife/environment_show.rb @@ -22,18 +22,13 @@ class Chef class Knife class EnvironmentShow < Knife + include Knife::Core::MultiAttributeRetrunOption + deps do require 'chef/environment' require 'chef/json_compat' end - @attrs_to_show = [] - option :attribute, - :short => "-a [ATTR]", - :long => "--attribute [ATTR]", - :proc => lambda {|val| @attrs_to_show << val}, - :description => "Show one or more attributes" - banner "knife environment show ENVIRONMENT (options)" def run diff --git a/lib/chef/knife/node_show.rb b/lib/chef/knife/node_show.rb index 4b0be18890..da2a5940ba 100644 --- a/lib/chef/knife/node_show.rb +++ b/lib/chef/knife/node_show.rb @@ -24,6 +24,7 @@ class Chef class NodeShow < Knife include Knife::Core::NodeFormattingOptions + include Knife::Core::MultiAttributeRetrunOption deps do require 'chef/node' @@ -32,13 +33,6 @@ class Chef banner "knife node show NODE (options)" - @attrs_to_show = [] - option :attribute, - :short => "-a [ATTR]", - :long => "--attribute [ATTR]", - :proc => lambda {|val| @attrs_to_show << val}, - :description => "Show one or more attributes" - option :run_list, :short => "-r", :long => "--run-list", diff --git a/lib/chef/knife/role_show.rb b/lib/chef/knife/role_show.rb index 2f09794cbb..0b4ac50209 100644 --- a/lib/chef/knife/role_show.rb +++ b/lib/chef/knife/role_show.rb @@ -22,6 +22,8 @@ class Chef class Knife class RoleShow < Knife + include Knife::Core::MultiAttributeRetrunOption + deps do require 'chef/node' require 'chef/json_compat' @@ -29,10 +31,6 @@ class Chef banner "knife role show ROLE (options)" - option :attribute, - :short => "-a ATTR", - :long => "--attribute ATTR", - :description => "Show only one attribute" def run @role_name = @name_args[0] diff --git a/lib/chef/knife/search.rb b/lib/chef/knife/search.rb index 0d348d978a..eefde52395 100644 --- a/lib/chef/knife/search.rb +++ b/lib/chef/knife/search.rb @@ -23,6 +23,8 @@ class Chef class Knife class Search < Knife + include Knife::Core::MultiAttributeRetrunOption + deps do require 'chef/node' require 'chef/environment' @@ -54,11 +56,6 @@ class Chef :default => 1000, :proc => lambda { |i| i.to_i } - option :attribute, - :short => "-a ATTR", - :long => "--attribute ATTR", - :description => "Show only one attribute" - option :run_list, :short => "-r", :long => "--run-list", diff --git a/lib/chef/knife/user_show.rb b/lib/chef/knife/user_show.rb index 5088210b4d..d923cafcec 100644 --- a/lib/chef/knife/user_show.rb +++ b/lib/chef/knife/user_show.rb @@ -22,6 +22,8 @@ class Chef class Knife class UserShow < Knife + include Knife::Core::MultiAttributeRetrunOption + deps do require 'chef/user' require 'chef/json_compat' @@ -29,11 +31,6 @@ class Chef banner "knife user show USER (options)" - option :attribute, - :short => "-a ATTR", - :long => "--attribute ATTR", - :description => "Show only one attribute" - def run @user_name = @name_args[0] diff --git a/spec/unit/knife/core/ui_spec.rb b/spec/unit/knife/core/ui_spec.rb index 1513a66797..0b6978596a 100644 --- a/spec/unit/knife/core/ui_spec.rb +++ b/spec/unit/knife/core/ui_spec.rb @@ -234,6 +234,12 @@ EOM @ui.config[:attribute] = "gi.go" @ui.format_for_display(input).should == { "sample-data-bag-item" => { "gi.go" => "ge" } } end + + it "should return multiple attributes" do + input = { "gi" => "go", "hi" => "ho", "id" => "sample-data-bag-item" } + @ui.config[:attribute] = ["gi", "hi"] + @ui.format_for_display(input).should == { "sample-data-bag-item" => { "gi" => "go", "hi"=> "ho" } } + end end describe "with --run-list passed" do |