summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRanjib Dey <ranjib@pagerduty.com>2013-04-11 20:54:22 -0700
committerBryan McLellan <btm@opscode.com>2013-05-24 10:27:03 -0700
commit4133160972a9972a9a062579504faa40eaa4c8db (patch)
treef74b21723c15cb0abc0420f16ef1ee50662e3120
parent1e2dd728f8d9ad724aa2980d5fb15c2e26d6bed8 (diff)
downloadchef-4133160972a9972a9a062579504faa40eaa4c8db.tar.gz
multi attribute return
-rw-r--r--lib/chef/knife/client_show.rb7
-rw-r--r--lib/chef/knife/core/generic_presenter.rb16
-rw-r--r--lib/chef/knife/environment_show.rb9
-rw-r--r--lib/chef/knife/node_show.rb8
-rw-r--r--lib/chef/knife/role_show.rb6
-rw-r--r--lib/chef/knife/search.rb7
-rw-r--r--lib/chef/knife/user_show.rb7
-rw-r--r--spec/unit/knife/core/ui_spec.rb6
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