Skip to content

Commit

Permalink
send paths to stdout (#12054)
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded authored Sep 7, 2022
1 parent 732fddc commit 4bff533
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 30 deletions.
15 changes: 3 additions & 12 deletions conan/cli/commands/cache.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import json

from conan.api.conan_api import ConanAPIV2
from conan.api.output import ConanOutput
from conan.cli.command import conan_command, COMMAND_GROUPS, conan_subcommand
from conan.cli.command import conan_command, COMMAND_GROUPS, conan_subcommand, cli_out_write
from conan.cli.commands.list import json_formatter
from conans.errors import ConanException
from conans.model.package_ref import PkgReference
Expand All @@ -15,11 +12,7 @@ def cache(conan_api: ConanAPIV2, parser, *args):
pass


def json_cache_path(res):
return json.dumps(res, indent=4)


@conan_subcommand(formatters={"json": json_cache_path})
@conan_subcommand()
def cache_path(conan_api: ConanAPIV2, parser, subparser, *args):
"""
Shows the path af a given reference
Expand Down Expand Up @@ -56,9 +49,7 @@ def cache_path(conan_api: ConanAPIV2, parser, subparser, *args):
else:
path = method(pref)

out = ConanOutput()
out.writeln(path)
return {"ref": args.reference, "folder": args.folder, "path": path}
cli_out_write(path)


def _get_recipe_reference(reference):
Expand Down
8 changes: 3 additions & 5 deletions conan/cli/commands/profile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from conan.api.output import ConanOutput
from conan.cli.command import conan_command, conan_subcommand, COMMAND_GROUPS
from conan.cli.command import conan_command, conan_subcommand, COMMAND_GROUPS, cli_out_write
from conan.cli.commands import json_formatter
from conan.cli.common import add_profiles_args, get_profiles_from_args
from conans.errors import ConanException
Expand Down Expand Up @@ -42,7 +42,7 @@ def profile_show(conan_api, parser, subparser, *args):
return result


@conan_subcommand(formatters={"text": lambda x: x, "json": json_formatter})
@conan_subcommand()
def profile_path(conan_api, parser, subparser, *args):
"""
Show profile path location
Expand All @@ -51,9 +51,7 @@ def profile_path(conan_api, parser, subparser, *args):
subparser.add_argument("name", help="Profile name")
args = parser.parse_args(*args)
result = conan_api.profiles.get_path(args.name)
out = ConanOutput()
out.writeln(result)
return result
cli_out_write(result)


@conan_subcommand()
Expand Down
7 changes: 7 additions & 0 deletions conans/test/integration/command/test_profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from conans.test.utils.tools import TestClient


def test_profile_path():
c = TestClient()
c.run("profile path default")
assert "default" in c.out
13 changes: 0 additions & 13 deletions conans/test/integration/command_v2/test_cache_path.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import copy
import json

import pytest
Expand Down Expand Up @@ -125,15 +124,3 @@ def test_cache_path_regular_errors(created_package):

t.run("cache path patata/1.0#123123", assert_error=True)
assert "ERROR: No entry for recipe 'patata/1.0#123123'" in t.out


def test_cache_path_regular_json_output_format(created_package):
t, pref = created_package

# JSON output
t.run("cache path {} --folder package --format json".format(pref.repr_notime()))
data = json.loads(t.stdout)
path = t.cache.pkg_layout(pref).package()
assert data["ref"] == pref.repr_notime()
assert data["folder"] == "package"
assert data["path"] == path

0 comments on commit 4bff533

Please sign in to comment.