Skip to content

Commit

Permalink
profile show --format=json (#14743)
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded authored Sep 15, 2023
1 parent aded369 commit 5353d85
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
10 changes: 9 additions & 1 deletion conan/cli/commands/profile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import os

from conan.api.output import ConanOutput, cli_out_write
Expand All @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions conans/test/integration/command/test_profile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import os

from conans.test.utils.tools import TestClient
Expand Down Expand Up @@ -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"}

0 comments on commit 5353d85

Please sign in to comment.