-
-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #493 from mattbennett/config-command
add a command to output parsed config after env var substitution
- Loading branch information
Showing
3 changed files
with
77 additions
and
0 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,11 @@ | ||
from __future__ import print_function | ||
|
||
import yaml | ||
|
||
|
||
def main(args): | ||
|
||
with open(args.config) as fle: | ||
config = yaml.load(fle) | ||
|
||
print(yaml.dump(config, default_flow_style=False)) |
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,41 @@ | ||
from textwrap import dedent | ||
|
||
from mock import patch | ||
|
||
from nameko.cli.commands import ShowConfig | ||
from nameko.cli.main import setup_parser, setup_yaml_parser | ||
|
||
|
||
@patch('nameko.cli.main.os') | ||
def test_main(mock_os, tmpdir, capsys): | ||
|
||
config = tmpdir.join('config.yaml') | ||
config.write(""" | ||
FOO: ${FOO:foobar} | ||
BAR: ${BAR} | ||
""") | ||
|
||
parser = setup_parser() | ||
setup_yaml_parser() | ||
args = parser.parse_args([ | ||
'show-config', | ||
'--config', | ||
config.strpath, | ||
]) | ||
|
||
mock_os.environ = { | ||
'BAR': '[1,2,3]' | ||
} | ||
|
||
ShowConfig.main(args) | ||
out, _ = capsys.readouterr() | ||
|
||
expected = dedent(""" | ||
BAR: | ||
- 1 | ||
- 2 | ||
- 3 | ||
FOO: foobar | ||
""").strip() | ||
|
||
assert out.strip() == expected |