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

Saving profile list as a json file #5954

Merged
merged 2 commits into from Oct 22, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion conans/client/command.py
Expand Up @@ -1524,7 +1524,9 @@ def profile(self, *args):
subparsers.required = True

# create the parser for the "profile" command
subparsers.add_parser('list', help='List current profiles')
parser_list = subparsers.add_parser('list', help='List current profiles')
parser_list.add_argument("-j", "--json", default=None, action=OnceArgument,
help='json file path where the profile list will be written to')
parser_show = subparsers.add_parser('show', help='Show the values defined for a profile')
parser_show.add_argument('profile', help="name of the profile in the '.conan/profiles' "
"folder or path to a profile file")
Expand Down Expand Up @@ -1560,6 +1562,8 @@ def profile(self, *args):
if args.subcommand == "list":
profiles = self._conan.profile_list()
self._outputer.profile_list(profiles)
if args.json:
self._outputer.json_output(profiles, args.json, os.getcwd())
elif args.subcommand == "show":
profile_text = self._conan.read_profile(profile)
self._outputer.print_profile(profile, profile_text)
Expand Down
10 changes: 10 additions & 0 deletions conans/test/functional/command/profile_test.py
Expand Up @@ -5,6 +5,7 @@
from conans.test.utils.tools import TestClient
from conans.util.files import load
import platform
import json


class ProfileTest(unittest.TestCase):
Expand Down Expand Up @@ -51,6 +52,15 @@ def list_test(self):
profiles.sort()
self.assertEqual(profiles, list(str(client.out).splitlines()))

# Test profile list json file
client.run("profile list --json profile_list.json")
json_path = os.path.join(client.current_folder, "profile_list.json")
self.assertTrue(os.path.exists(json_path))
json_content = load(json_path)
json_obj = json.loads(json_content)
self.assertEqual(list, type(json_obj))
self.assertEqual(profiles, json_obj)

def show_test(self):
client = TestClient()
create_profile(client.cache.profiles_path, "profile1", settings={"os": "Windows"},
Expand Down