From bf6879d454dfc6f9bc5ce6c3271b9ff0bbd98ff3 Mon Sep 17 00:00:00 2001 From: memsharded Date: Fri, 15 Sep 2023 01:07:52 +0200 Subject: [PATCH] profile show --format=json --- conan/cli/commands/profile.py | 10 +++++++++- conans/test/integration/command/test_profile.py | 11 +++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/conan/cli/commands/profile.py b/conan/cli/commands/profile.py index bb3254fe523..27abff00d1f 100644 --- a/conan/cli/commands/profile.py +++ b/conan/cli/commands/profile.py @@ -1,3 +1,4 @@ +import json import os from conan.api.output import ConanOutput, cli_out_write @@ -22,7 +23,14 @@ def profiles_list_cli_output(profiles): cli_out_write(p) -@conan_subcommand(formatters={"text": print_profiles}) +def json_profiles(profiles): + host, build = profiles + result = {"host": host.serialize(), + "build": build.serialize()} + cli_out_write(json.dumps(result)) + + +@conan_subcommand(formatters={"text": print_profiles, "json": json_profiles}) def profile_show(conan_api, parser, subparser, *args): """ Show aggregated profiles from the passed arguments. diff --git a/conans/test/integration/command/test_profile.py b/conans/test/integration/command/test_profile.py index 2cc252e3ce2..86207bb4678 100644 --- a/conans/test/integration/command/test_profile.py +++ b/conans/test/integration/command/test_profile.py @@ -1,3 +1,4 @@ +import json import os from conans.test.utils.tools import TestClient @@ -28,3 +29,13 @@ def test_ignore_paths_when_listing_profiles(): c.run("profile list") assert ignore_path not in c.out + + +def test_profile_show_json(): + c = TestClient() + c.save({"myprofilewin": "[settings]\nos=Windows", + "myprofilelinux": "[settings]\nos=Linux"}) + c.run("profile show -pr:b=myprofilewin -pr:h=myprofilelinux --format=json") + profile = json.loads(c.stdout) + assert profile["build"]["settings"] == {"os": "Windows"} + assert profile["host"]["settings"] == {"os": "Linux"}