Skip to content

Commit 1064e8d

Browse files
committed
Add multiple node capabilities to --hostname option
1 parent 8774031 commit 1064e8d

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

lib/octocatalog-diff/cli.rb

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,24 @@ def self.cli(argv = ARGV, logger = Logger.new(STDERR), opts = {})
116116
end
117117

118118
# Compile catalogs and do catalog-diff
119-
catalog_diff = OctocatalogDiff::API::V1.catalog_diff(options.merge(logger: logger))
120-
diffs = catalog_diff.diffs
121-
122-
# Display diffs
123-
printer_obj = OctocatalogDiff::Cli::Printer.new(options, logger)
124-
printer_obj.printer(diffs, catalog_diff.from.compilation_dir, catalog_diff.to.compilation_dir)
119+
node_set = options.delete(:node)
120+
all_diffs = []
121+
node_set.each do |node|
122+
options[:node] = node
123+
catalog_diff = OctocatalogDiff::API::V1.catalog_diff(options.merge(logger: logger))
124+
diffs = catalog_diff.diffs
125+
126+
# Display diffs
127+
printer_obj = OctocatalogDiff::Cli::Printer.new(options, logger)
128+
printer_obj.printer(diffs, catalog_diff.from.compilation_dir, catalog_diff.to.compilation_dir)
129+
130+
# Append any diffs for final exit status
131+
all_diffs << diffs
132+
end
125133

126134
# Return the resulting diff object if requested (generally for testing) or otherwise return exit code
127135
return catalog_diff if opts[:INTEGRATION]
128-
diffs.any? ? EXITCODE_SUCCESS_WITH_DIFFS : EXITCODE_SUCCESS_NO_DIFFS
136+
all_diffs.any? ? EXITCODE_SUCCESS_WITH_DIFFS : EXITCODE_SUCCESS_NO_DIFFS
129137
end
130138

131139
# Parse command line options with 'optparse'. Returns a hash with the parsed arguments.

lib/octocatalog-diff/cli/options/hostname.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
def parse(parser, options)
1111
parser.on('--hostname HOSTNAME', '-n', 'Use PuppetDB facts from last run of hostname') do |hostname|
12-
options[:node] = hostname
12+
options[:node] = hostname.split(',')
1313
end
1414
end
1515
end

spec/octocatalog-diff/tests/cli/options/hostname_spec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
describe '#opt_hostname' do
77
it 'should set options[:node] when hostname is set with short form' do
88
result = run_optparse(['-n', 'octonode.rspec'])
9-
expect(result.fetch(:node, 'key-not-defined')).to eq('octonode.rspec')
9+
expect(result.fetch(:node, 'key-not-defined')).to eq(%w[octonode.rspec])
10+
end
11+
12+
it 'should set multiple nodes when passed a series of nodes' do
13+
result = run_optparse(['-n', 'octonode1.rspec,octonode2.rspec'])
14+
expect(result.fetch(:node, 'key-not-defined')).to eq(%w[octonode1.rspec octonode2.rspec])
1015
end
1116
end
1217
end

0 commit comments

Comments
 (0)