Permalink
Browse files

Move the YAML parsing option to `--filters`

  • Loading branch information...
1 parent fbeb740 commit 557c88f447ec17f15d34af8dcd224a11aa964ccf @kpaulisse kpaulisse committed Jan 7, 2017
@@ -0,0 +1,23 @@
+# Filters
+
+It is possible to enable additional filters for output results via the `--filters` command line option. This command line option accepts a comma-separated list of additional filters, and applies them to the results in the order you specify. The default behavior is not to use any of these filters.
+
+Please note that there are other options to ignore specified diffs, including:
+
+- [Ignoring by type, title, attribute, value, ...](/doc/advanced-ignores.md)
+
+Here is the list of available filters and an explanation of each:
+
+## YAML
+
+#### Usage
+
+```
+--filters YAML
+```
+
+#### Description
+
+If a file resource has extension `.yml` or `.yaml` and a difference in its content is observed, YAML objects are constructed from the previous and new values. If these YAML objects are identical, the difference is ignored.
+
+This allows you to ignore changes in whitespace, comments, etc., that are not meaningful to a machine parsing the file. Please note that by filtering these changes, you are ignoring changes to comments, which may be meaningful to humans.
View
@@ -46,8 +46,8 @@ Usage: octocatalog-diff [command line options]
--no-hiera-path-strip Do not use any default hiera path strip settings
--ignore-attr "attr1,attr2,..."
Attributes to ignore
- --[no-]ignore-equivalent-yaml-files
- Ignore YAML files differing only by whitespace
+ --filters FILTER1[,FILTER2[,...]]
+ Filters to apply
--[no-]display-source Show source file and line for each difference
--[no-]validate-references "before,require,subscribe,notify"
References to validate
@@ -428,6 +428,20 @@ on which this is running. (<a href="../lib/octocatalog-diff/catalog-diff/cli/opt
<tr>
<td valign=top>
+ <pre><code>--filters FILTER1[,FILTER2[,...]]</code></pre>
+ </td>
+ <td valign=top>
+ Filters to apply
+ </td>
+ <td valign=top>
+ Specify one or more filters to apply to the results of the catalog difference.
+For a list of available filters and further explanation, please refer to
+[Filtering results](/doc/advanced-filter.md). (<a href="../lib/octocatalog-diff/catalog-diff/cli/options/filters.rb">filters.rb</a>)
+ </td>
+ </tr>
+
+ <tr>
+ <td valign=top>
<pre><code>-f FROM_BRANCH
--from FROM_BRANCH</code></pre>
</td>
@@ -566,19 +580,6 @@ Puppet control repo template, the value of this should be 'hieradata', which is
<tr>
<td valign=top>
- <pre><code>--ignore-equivalent-yaml-files
---no-ignore-equivalent-yaml-files </code></pre>
- </td>
- <td valign=top>
- Ignore YAML files differing only by whitespace
- </td>
- <td valign=top>
- Ignore difference between YAML files if they contain the same content differing only by whitespace. (<a href="../lib/octocatalog-diff/catalog-diff/cli/options/ignore_equivalent_yaml_files.rb">ignore_equivalent_yaml_files.rb</a>)
- </td>
- </tr>
-
- <tr>
- <td valign=top>
<pre><code>--ignore-tags STRING1[,STRING2[,...]]</code></pre>
</td>
<td valign=top>
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+# Specify one or more filters to apply to the results of the catalog difference.
+# For a list of available filters and further explanation, please refer to
+# [Filtering results](/doc/advanced-filter.md).
+# @param parser [OptionParser object] The OptionParser argument
+# @param options [Hash] Options hash being constructed; this is modified in this method.
+OctocatalogDiff::CatalogDiff::Cli::Options::Option.newoption(:filters) do
+ has_weight 199
+
+ def parse(parser, options)
+ parser.on('--filters FILTER1[,FILTER2[,...]]', Array, 'Filters to apply') do |x|
+ options[:filters] ||= []
+ options[:filters].concat x
+ end
+ end
+end
@@ -1,14 +0,0 @@
-# frozen_string_literal: true
-
-# Ignore difference between YAML files if they contain the same content differing only by whitespace.
-# @param parser [OptionParser object] The OptionParser argument
-# @param options [Hash] Options hash being constructed; this is modified in this method.
-OctocatalogDiff::CatalogDiff::Cli::Options::Option.newoption(:ignore_equivalent_yaml_files) do
- has_weight 199
-
- def parse(parser, options)
- parser.on('--[no-]ignore-equivalent-yaml-files', 'Ignore YAML files differing only by whitespace') do |x|
- options[:ignore_equivalent_yaml_files] = x
- end
- end
-end
@@ -154,12 +154,8 @@ def catdiff
# out any such parameters from the result array.
filter_diffs_for_absent_files(result) if @opts[:suppress_absent_file_details]
- # If --ignore-equivalent-yaml-files is specified, then for any YAML file that is changed, parse the YAML
- # to construct the object. If the objects are identical this means the YAML file differs only in whitespace
- # or comments but not in function. Remove these.
- if @opts[:ignore_equivalent_yaml_files]
- OctocatalogDiff::CatalogDiff::Filter.filter(result, 'YAML')
- end
+ # Apply any additional pluggable filters.
+ OctocatalogDiff::CatalogDiff::Filter.apply_filters(result, @opts[:filters])
# That's it!
@logger.debug "Exiting catdiff; change count: #{result.size}"
@@ -11,6 +11,7 @@ class Filter
# @param filter_names [Array] Filters to run
# @param options [Hash] Options for each filter (hashed by name)
def self.apply_filters(result, filter_names, options = {})
+ return unless filter_names.is_a?(Array)
filter_names.each { |x| filter(result, x, options[x] || {}) }
end
@@ -47,7 +47,7 @@
context 'with YAML diff suppression enabled' do
before(:all) do
- argv = ['-n', 'rspec-node.github.net', '--to-fact-override', 'role=bar', '--ignore-equivalent-yaml-files']
+ argv = ['-n', 'rspec-node.github.net', '--to-fact-override', 'role=bar', '--filters', 'YAML']
hash = { hiera_config: 'hiera.yaml', spec_fact_file: 'facts.yaml', spec_repo: 'yaml-diff' }
@result = OctocatalogDiff::Integration.integration(hash.merge(argv: argv))
end
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+require_relative '../options_helper'
+
+describe OctocatalogDiff::CatalogDiff::Cli::Options do
+ describe '#opt_ignore_equivalent_yaml_files' do
+ it 'should accept comma delimited parameters for --filters' do
+ result = run_optparse(['--filters', 'fizzbuzz,barbuzz'])
+ expect(result[:filters]).to eq(%w(fizzbuzz barbuzz))
+ end
+
+ it 'should accept multiple parameters for --filters' do
+ result = run_optparse(['--filters', 'fizzbuzz', '--filters', 'barbuzz'])
+ expect(result[:filters]).to eq(%w(fizzbuzz barbuzz))
+ end
+ end
+end
@@ -1,9 +0,0 @@
-# frozen_string_literal: true
-
-require_relative '../options_helper'
-
-describe OctocatalogDiff::CatalogDiff::Cli::Options do
- describe '#opt_ignore_equivalent_yaml_files' do
- include_examples 'true/false option', 'ignore-equivalent-yaml-files', :ignore_equivalent_yaml_files
- end
-end
@@ -662,29 +662,6 @@
end
end
- context 'additional pluggable filters' do
- context 'equivalent YAML files with different text representations' do
- before(:all) do
- @c1 = OctocatalogDiff::Catalog.new(json: OctocatalogDiff::Spec.fixture_read('catalogs/ignore-equivalent-yaml-1.json'))
- @c2 = OctocatalogDiff::Catalog.new(json: OctocatalogDiff::Spec.fixture_read('catalogs/ignore-equivalent-yaml-2.json'))
- end
-
- it 'should filter when filter is enabled' do
- opts = { ignore_equivalent_yaml_files: true }
- testobj = OctocatalogDiff::CatalogDiff::Differ.new(opts, @c1, @c2)
- result = testobj.diff
- expect(result.size).to eq(0)
- end
-
- it 'should not filter when filter is disabled' do
- opts = {}
- testobj = OctocatalogDiff::CatalogDiff::Differ.new(opts, @c1, @c2)
- result = testobj.diff
- expect(result.size).to eq(1)
- end
- end
- end
-
context 'ignoring specific changes in attributes' do
before(:all) do
@c1 = OctocatalogDiff::Catalog.new(json: OctocatalogDiff::Spec.fixture_read('catalogs/ignore-enhanced-changes-1.json'))

0 comments on commit 557c88f

Please sign in to comment.