-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(PDK-1107) Add pdk config get CLI command
Previously there was no way to display what the current configuration the PDK was using. This commit adds a `pdk config` command, with a single `get` sub-command. This commit also adds the ability to filter the settings either by a specific name or setting treename. This commit also adds tests for the new resolve method in the Namespace object.
- Loading branch information
1 parent
050fbc1
commit f613c8c
Showing
9 changed files
with
202 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module PDK::CLI | ||
@config_cmd = @base_cmd.define_command do | ||
name 'config' | ||
usage _('config [subcommand] [options]') | ||
summary _('Configure the Puppet Development Kit.') | ||
default_subcommand 'get' | ||
|
||
run do |_opts, args, _cmd| | ||
if args == ['help'] | ||
PDK::CLI.run(%w[config --help]) | ||
exit 0 | ||
end | ||
|
||
PDK::CLI.run(%w[config get]) if args.empty? | ||
end | ||
end | ||
@config_cmd.add_command Cri::Command.new_basic_help | ||
end | ||
|
||
require 'pdk/cli/config/get' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module PDK::CLI | ||
@config_get_cmd = @config_cmd.define_command do | ||
name 'get' | ||
usage _('config get [name]') | ||
summary _('Retrieve the configuration for <name>. If not specified, retrieve all configuration settings') | ||
|
||
run do |_opts, args, _cmd| | ||
item_name = args[0] | ||
resolved_config = PDK::Config.new.resolve(item_name) | ||
# If the user wanted to know a setting but it doesn't exist, raise an error | ||
if resolved_config.empty? && !item_name.nil? | ||
PDK.logger.error(_("Configuration item '%{name}' does not exist") % { name: item_name }) | ||
exit 1 | ||
end | ||
resolved_config.keys.sort.each { |key| puts _('%{name}=%{value}') % { name: key, value: resolved_config[key] } } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require 'spec_helper_acceptance' | ||
require 'fileutils' | ||
|
||
describe 'pdk config get' do | ||
include_context 'with a fake TTY' | ||
|
||
context 'when run outside of a module' do | ||
describe command('pdk config get') do | ||
its(:exit_status) { is_expected.to eq 0 } | ||
# This setting should appear in all pdk versions | ||
its(:stdout) { is_expected.to match(%r{user\.analytics\.user-id=}) } | ||
its(:stderr) { is_expected.to be_empty } | ||
end | ||
|
||
describe command('pdk config get user.analytics.disabled') do | ||
its(:exit_status) { is_expected.to eq 0 } | ||
# This setting, and only, this setting should appear in output | ||
its(:stdout) { is_expected.to eq("user.analytics.disabled=true\n") } | ||
its(:stderr) { is_expected.to be_empty } | ||
end | ||
|
||
describe command('pdk config get user.analytics') do | ||
its(:exit_status) { is_expected.to eq 0 } | ||
# There should be two configuration items returned | ||
its(:stdout) { expect(is_expected.target.split("\n").count).to eq(2) } | ||
its(:stdout) do | ||
result = is_expected.target.split("\n").sort | ||
expect(result[0]).to match('user.analytics.disabled=true') | ||
expect(result[1]).to match(%r{user.analytics.user-id=.+}) | ||
end | ||
its(:stderr) { is_expected.to be_empty } | ||
end | ||
|
||
describe command('pdk config get does.not.exist') do | ||
its(:exit_status) { is_expected.not_to eq(0) } | ||
its(:stdout) { is_expected.to be_empty } | ||
its(:stderr) { is_expected.to match(%r{does\.not\.exist}) } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'spec_helper_acceptance' | ||
require 'fileutils' | ||
|
||
describe 'pdk config' do | ||
include_context 'with a fake TTY' | ||
|
||
context 'when run outside of a module' do | ||
describe command('pdk config') do | ||
its(:exit_status) { is_expected.to eq 0 } | ||
# This setting should appear in all pdk versions | ||
its(:stdout) { is_expected.to match(%r{user\.analytics\.user-id=}) } | ||
its(:stderr) { is_expected.to be_empty } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters