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

profile show --format=json #14743

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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"}