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

Add format json option to conan cache path #15613

Merged
merged 3 commits into from
Feb 7, 2024

Conversation

juansblanco
Copy link
Contributor

@juansblanco juansblanco commented Feb 6, 2024

Changelog: Feature: Add --format=json option to conan cache path.
Docs: Omit

Added --format=json option to the conan cache path command that returns a json as:
{"cache_path": "C:\\Users\\user\\.conan2\\p\\zlib2cad50ee1214e\\e"}

Closes: #15599

@juansblanco juansblanco added this to the 2.1 milestone Feb 6, 2024
juansblanco and others added 2 commits February 7, 2024 10:54
Co-authored-by: Rubén Rincón Blanco <git@rinconblanco.es>
Co-authored-by: James <memsharded@gmail.com>
@jcar87
Copy link
Contributor

jcar87 commented Feb 7, 2024

LGTM as it is, but I wonder if we might want something slightly more elaborate?

At the moment, the following two invocationS:

conan cache path foo/1.0.0 --format=json

and

conan cache path foo/1.0.0 --folder=metadata --format=json

would both return a json have the key cache_path in the returned json, but pointing to a different folder. This mirrors the behaviour of the regular CLI output, but it makes me wonder if we might want something more "rich"?

e.g.

{
    "cache_path": "C:\\Users\\user\\.conan2\\p\\zlib2cad50ee1214e\\e", 
    "folder": "exports", 
    "reference": "foo/1.0.0"
}

and

   "cache_path": "xxx",
   "folder: "metadata", 
   "reference: "foo/1.0.0"

or even a richer

{
 "ref": "foo/1.0.0#rrev1", 
 "folders": 
     { 
         "exports": "path1",
         "metadata": "path2"
         "export_source": "path3",
         // etc...
      }
}

Just an idea, but perhaps if we decide to do something richer in the future, leave the json today in a way that can be extended without breaking?

@memsharded
Copy link
Member

I think it should be good enough with the command to return 1 path only because all the use cases I have found so far it is to do operations on 1 folder, like the metadata one, but it is unlikely to need several folders, and it that is the case they can do several conan cache path calls, not a big issue. So the

{
    "cache_path": "C:\\Users\\user\\.conan2\\p\\zlib2cad50ee1214e\\e", 
    "folder": "exports", 
    "reference": "foo/1.0.0"
}

Should be future-proof enough, and maybe if we want a multiple-paths command and accept multiple --folder arguments, the output format can change anyway to accommodate for that, as this would be an opt-in.

Because for the basic case I am concerned that you'd need to use both the argumetn --folder=xxxx and then yet again the same in the jq query or to parse the json with data["folders"][xxxxx] to get the value you requested as an argument?

So I think might be good as-is

@jcar87
Copy link
Contributor

jcar87 commented Feb 7, 2024

Makes sense! Merging :) Thanks @juansblanco !!

@jcar87 jcar87 merged commit 9545dcc into conan-io:develop2 Feb 7, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feature] add --format=json to conan cache path
4 participants