Skip to content

Commit

Permalink
Merge pull request #166 from chef/nim/support_format_option
Browse files Browse the repository at this point in the history
Support --format option
  • Loading branch information
JJ Asghar committed Jun 25, 2015
2 parents a9d51ea + 3683cbf commit cd015cb
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 18 deletions.
41 changes: 23 additions & 18 deletions lib/chef/knife/openstack_group_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,32 @@ def query_resource
end

def list(security_groups)
group_list = [
ui.color('Name', :bold),
ui.color('Protocol', :bold),
ui.color('From', :bold),
ui.color('To', :bold),
ui.color('CIDR', :bold),
ui.color('Description', :bold),
]
security_groups.sort_by(&:name).each do |group|
group.security_group_rules.each do |rule|
unless rule.ip_protocol.nil?
group_list << group.name
group_list << rule.ip_protocol
group_list << rule.from_port.to_s
group_list << rule.to_port.to_s
group_list << rule.ip_range['cidr']
group_list << group.description
if(config[:format] == "summary")
group_list = [
ui.color('Name', :bold),
ui.color('Protocol', :bold),
ui.color('From', :bold),
ui.color('To', :bold),
ui.color('CIDR', :bold),
ui.color('Description', :bold),
]
security_groups.sort_by(&:name).each do |group|
group.security_group_rules.each do |rule|
unless rule.ip_protocol.nil?
group_list << group.name
group_list << rule.ip_protocol
group_list << rule.from_port.to_s
group_list << rule.to_port.to_s
group_list << rule.ip_range['cidr']
group_list << group.description
end
end
end

puts ui.list(group_list, :uneven_columns_across, 6)
else
output(format_for_display(security_groups))
end
puts ui.list(group_list, :uneven_columns_across, 6)
end
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/functional/flavor_list_func_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
allow(instance).to receive(:puts)
allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new)
allow(instance).to receive(:validate!)
instance.config[:format] = "summary"
end

it "lists formatted list of resources" do
Expand Down
1 change: 1 addition & 0 deletions spec/functional/group_list_func_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
allow(instance).to receive(:puts)
allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new)
allow(instance).to receive(:validate!)
instance.config[:format] = "summary"
end

it "lists formatted list of resources" do
Expand Down
1 change: 1 addition & 0 deletions spec/functional/image_list_func_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
allow(instance).to receive(:puts)
allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new)
allow(instance).to receive(:validate!)
instance.config[:format] = "summary"
end

it "displays formatted list of images, filtered by default" do
Expand Down
1 change: 1 addition & 0 deletions spec/functional/network_list_func_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
allow(instance).to receive(:puts)
allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::Service.new)
allow(instance).to receive(:validate!)
instance.config[:format] = "summary"
end

it "lists formatted list of network resources" do
Expand Down
1 change: 1 addition & 0 deletions spec/functional/server_list_func_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
allow(instance).to receive(:puts)
allow(instance).to receive(:create_service_instance).and_return(Chef::Knife::Cloud::FogService.new)
allow(instance).to receive(:validate!)
instance.config[:format] = "summary"
end

it "lists formatted list of resources" do
Expand Down
1 change: 1 addition & 0 deletions spec/unit/openstack_group_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
context "#list" do
before(:each) do
@security_groups = [TestResource.new({ "name" => "Unrestricted","description" => "testdescription", "security_group_rules" => [TestResource.new({"from_port"=>636, "group"=>{}, "ip_protocol"=>"tcp", "to_port"=>636, "parent_group_id"=>14, "ip_range"=>{"cidr"=>"0.0.0.0/0"}, "id"=>183})]})]
instance.config[:format] = "summary"
end

it "returns group list" do
Expand Down

0 comments on commit cd015cb

Please sign in to comment.