Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #26961 - Filter fields properly #307

Merged
merged 1 commit into from Jun 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/hammer_cli/output/adapter/abstract.rb
Expand Up @@ -92,7 +92,7 @@ def classes_filter
end

def sets_filter
@context[:fields] || []
@context[:fields] || ['DEFAULT']
end

private
Expand Down
7 changes: 2 additions & 5 deletions lib/hammer_cli/output/field_filter.rb
Expand Up @@ -65,12 +65,9 @@ def displayable_fields(fields, record, compact_only: false)
end

def include_by_label?(labels, label)
return true if labels.include?(label)

labels.each do |l|
return true if l.start_with?("#{label}/") || label.start_with?(l)
labels.any? do |l|
l.start_with?("#{label}/") || label.match(%r{^#{l.gsub(/\*/, '.*')}(|\/.*)$})
end
false
end

def resolve_set_names(sets)
Expand Down
2 changes: 1 addition & 1 deletion lib/hammer_cli/output/fields.rb
Expand Up @@ -32,7 +32,7 @@ def hide_missing?
end

def full_label
return @label if @parent.nil?
return @label.to_s if @parent.nil?
"#{@parent.full_label}/#{@label}"
end

Expand Down
12 changes: 11 additions & 1 deletion test/unit/output/field_filter_test.rb
Expand Up @@ -47,7 +47,17 @@

it 'filters by full labels' do
f = HammerCLI::Output::FieldFilter.new(container_fields, sets_filter: ['container/first'])
f.filter_by_sets.filtered_fields.map(&:label).must_equal ['container']
f.filter_by_sets.filtered_fields.first.fields.map(&:label).must_equal ['first']
end

it 'filters by superclass labels' do
f = HammerCLI::Output::FieldFilter.new(container_fields, sets_filter: ['container'])
f.filter_by_sets.filtered_fields.first.fields.map(&:label).must_equal ['first', 'second']
end

it 'filters by labels with wildcards' do
f = HammerCLI::Output::FieldFilter.new(container_fields, sets_filter: ['container/f*'])
f.filter_by_sets.filtered_fields.first.fields.map(&:label).must_equal ['first']
end

it 'allows chained filtering' do
Expand Down