Permalink
Browse files

multi attribute return

  • Loading branch information...
ranjib authored and btm committed Apr 12, 2013
1 parent 1e2dd72 commit 4133160972a9972a9a062579504faa40eaa4c8db
@@ -22,18 +22,15 @@ class Chef
class Knife
class ClientShow < Knife
include Knife::Core::MultiAttributeRetrunOption
deps do
require 'chef/api_client'
require 'chef/json_compat'
end
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]
@@ -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
@@ -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
@@ -24,6 +24,7 @@ class Knife
class NodeShow < Knife
include Knife::Core::NodeFormattingOptions
include Knife::Core::MultiAttributeRetrunOption
deps do
require 'chef/node'
@@ -32,13 +33,6 @@ class NodeShow < Knife
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",
@@ -22,17 +22,15 @@ class Chef
class Knife
class RoleShow < Knife
include Knife::Core::MultiAttributeRetrunOption
deps do
require 'chef/node'
require 'chef/json_compat'
end
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]
View
@@ -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 Search < Knife
: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",
@@ -22,18 +22,15 @@ class Chef
class Knife
class UserShow < Knife
include Knife::Core::MultiAttributeRetrunOption
deps do
require 'chef/user'
require 'chef/json_compat'
end
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]
@@ -234,6 +234,12 @@
@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

0 comments on commit 4133160

Please sign in to comment.