Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conan config show <conf> command #13354

Merged
merged 5 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions conan/api/subapi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ def install(self, path_or_url, verify_ssl, config_type=None, args=None,
def get(self, name, default=None, check_type=None):
app = ConanApp(self.conan_api.cache_folder)
return app.cache.new_config.get(name, default=default, check_type=check_type)

def show(self, pattern):
app = ConanApp(self.conan_api.cache_folder)
return app.cache.new_config.show(pattern)
11 changes: 11 additions & 0 deletions conan/cli/commands/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,14 @@ def config_list(conan_api, parser, subparser, *args):
"""
parser.parse_args(*args)
return BUILT_IN_CONFS


@conan_subcommand(formatters={"text": list_text_formatter, "json": default_json_formatter})
def config_show(conan_api, parser, subparser, *args):
"""
Get the value of the specified conf
"""
subparser.add_argument('pattern', help='Conf item(s) pattern for which to query their value')
args = parser.parse_args(*args)

return conan_api.config.show(args.pattern)
14 changes: 13 additions & 1 deletion conans/model/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
import os
import fnmatch

from collections import OrderedDict

Expand Down Expand Up @@ -306,6 +307,9 @@ def pop(self, conf_name, default=None):
self._values.pop(conf_name, None)
return value

def show(self, pattern):
return {key: self.get(key) for key in self._values.keys()if fnmatch.fnmatch(key, pattern)}

def copy(self):
c = Conf()
c._values = self._values.copy()
Expand Down Expand Up @@ -475,12 +479,20 @@ def __bool__(self):

def get(self, conf_name, default=None, check_type=None):
"""
Get the value of the conf name requested and convert it to the [type]-like passed.
Get the value of the conf name requested and convert it to the [type]-like passed.
"""
pattern, name = self._split_pattern_name(conf_name)
return self._pattern_confs.get(pattern, Conf()).get(name, default=default,
check_type=check_type)

def show(self, pattern):
result = {}

for p in self._pattern_confs.values():
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
result.update(p.show(pattern))

return result

def pop(self, conf_name, default=None):
"""
Remove the conf name passed.
Expand Down
25 changes: 25 additions & 0 deletions conans/test/integration/command/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,28 @@ def _assert_config_not_exists(path):
_assert_config_exists("foo")

os.listdir(tc.current_folder)


def test_config_show():
globalconf = textwrap.dedent("""
tools.build:jobs=42
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
tools.files.download:retry_wait=10
tools.files.download:retry=7
core.net.http:timeout=30
core.net.http:max_retries=5
""")
tc = TestClient()
tc.save_home({"global.conf": globalconf})
tc.run("config show tools.build:jobs")
assert "42" in tc.out

tc.run("config show core*")
assert "core.net.http:timeout" in tc.out
assert "30" in tc.out
assert "core.net.http:max_retries" in tc.out
assert "5" in tc.out

tc.run("config show *retr*")
assert "tools.files.download:retry_wait" in tc.out
assert "tools.files.download:retry" in tc.out
assert "core.net.http:max_retries" in tc.out