Skip to content

Commit 7ccf46a

Browse files
author
Kevin Paulisse
committed
Add --puppetdb-api-version commandline
1 parent 210e3c7 commit 7ccf46a

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Specify the API version to use for the PuppetDB. The current values supported are '3' or '4', and '4' is
2+
# the default.
3+
# @param parser [OptionParser object] The OptionParser argument
4+
# @param options [Hash] Options hash being constructed; this is modified in this method.
5+
OctocatalogDiff::CatalogDiff::Cli::Options::Option.newoption(:puppetdb_api_version) do
6+
has_weight 319
7+
8+
def parse(parser, options)
9+
parser.on('--puppetdb-api-version N', OptionParser::DecimalInteger, 'Version of PuppetDB API (3 or 4)') do |x|
10+
options[:puppetdb_api_version] = x
11+
raise ArgumentError, 'Only PuppetDB versions 3 and 4 are supported' unless [3, 4].include?(x)
12+
end
13+
end
14+
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require_relative '../options_helper'
2+
3+
describe OctocatalogDiff::CatalogDiff::Cli::Options do
4+
describe '#opt_puppetdb_api_version' do
5+
it 'should handle --puppetdb-api-version with API version 3' do
6+
result = run_optparse(['--puppetdb-api-version', '3'])
7+
expect(result[:puppetdb_api_version]).to eq(3)
8+
end
9+
10+
it 'should handle --puppetdb-api-version with API version 4' do
11+
result = run_optparse(['--puppetdb-api-version', '4'])
12+
expect(result[:puppetdb_api_version]).to eq(4)
13+
end
14+
15+
it 'should fail if --puppetdb-api-version is unsupported' do
16+
expect { run_optparse(['--puppetdb-api-version', '9000']) }.to raise_error(ArgumentError)
17+
end
18+
end
19+
end

0 commit comments

Comments
 (0)