Project

General

Profile

Actions

Feature #4231

closed

Need the ability to easily omit blank/nil values from command output

Added by Brad Buckingham over 10 years ago. Updated almost 6 years ago.

Status:
Closed
Priority:
High
Category:
Hammer core
Target version:
Difficulty:
Triaged:
Team Backlog:
Fixed in Releases:
Found in Releases:
In Kanboard:

Description

While working on the hammer cli for katello, I find that we really need the ability in the output format DSL to 'omit' attributes/fields that are nil (or blank).

Below is a scenario to describe why this is needed and useful.

For katello content view filters, a user may create a filter for the following types of content: package, package group, erratum or puppet module.

For each filter that the user creates, the 'parameters' for the filter may vary based upon the filter type, but also based upon what the user wants to define in the filter.

The following output format covers the possibilities:

label "Parameters" do
from :parameters do
collection :units, "Units" do
field :id, "ID"
field :name, "Name"
field :author, "Author"
field :version, "Version"
field :min_version, "Minimum Version"
field :max_version, "Maximum Version"
field :inclusion, "Include"
field :created_at, "Created"
end
label "Date Range" do
from :date_range do
field :start, "Start Date"
field :end, "End Date"
end
end
field :inclusion, "Include" 
field :created_at, "Created"
end
end

For a very simple package rule, to 'include zip 10.0', the command output looks like:

hammer> content_view filter info --id 4
Filter ID: 4
Name: filter1
Type: rpm
Repositories:
Parameters:
Units:
ID:
Name: zip
Author:
Version: 10.0
Minimum Version:
Maximum Version:
Include: true
Created: 2014-01-31T13:48:33Z

Date Range:         
Start Date:
End Date:
Include:
Created:

As you can see, there are a lot of empty fields.

Given that the filter can contain many different parameter units, we really need the ability to leave out all of the 'empty' fields that are not returned by the server. One possibility would be to specify this in the output format using something like ":include_blank? => false" when defining the output. For example, the above specification could become:

label "Parameters" do
from :parameters do
collection :units, "Units", :include_blank? => false do
field :id, "ID", :include_blank? => false
field :name, "Name", :include_blank? => false
field :author, "Author", :include_blank? => false
field :version, "Version", :include_blank? => false
field :min_version, "Minimum Version", :include_blank? => false
field :max_version, "Maximum Version", :include_blank? => false
field :inclusion, "Include", :include_blank? => false
field :created_at, "Created", :include_blank? => false
end
label "Date Range", :include_blank? => false do
from :date_range do
field :start, "Start Date", :include_blank? => false
field :end, "End Date", :include_blank? => false
end
end
field :inclusion, "Include" 
field :created_at, "Created"
end
end

With this, the same command could be streamlined to look like:

hammer> content_view filter info --id 4
Filter ID: 4
Name: filter1
Type: rpm
Repositories:
Parameters:
Units:
Name: zip
Version: 10.0
Include: true
Created: 2014-01-31T13:48:33Z

Actions #1

Updated by Tomáš Strachota over 10 years ago

  • Status changed from New to Assigned
  • Assignee set to Tomáš Strachota
Actions #2

Updated by Tomáš Strachota over 10 years ago

  • Target version set to 1.9.2
Actions #3

Updated by Anonymous over 10 years ago

  • Target version changed from 1.9.2 to 1.9.1
Actions #4

Updated by Tomáš Strachota about 10 years ago

  • Status changed from Assigned to Ready For Testing
Actions #5

Updated by Anonymous about 10 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

Applied in changeset foreman:hammer-cli|commit:88e19ee415423ed421a55c9daebc2dbec36ff6fe.

Actions

Also available in: Atom PDF