conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.27k stars 981 forks source link

[feature] support "conan remote get-url <remote_name>" cli-command #13195

Closed szy1840 closed 1 year ago

szy1840 commented 1 year ago

What is your suggestion?

I Need to write shell scripts to add a remote to conan, but it should check if the - pair already exists. It seems very silly if I have to use "conan remote list" and do some string matching. Just like in git we can do "git remote get-url ", I think It's good if conan can support this cli-command.

Have you read the CONTRIBUTING guide?

memsharded commented 1 year ago

Hi @szy1840

Thanks for your suggestion For such a task, it would not be necessary to do string matching the actual recommendation is to use the json output:

(conan2_36) λ conan remote list --format=json
[
    {
        "name": "myremote",
        "url": "https://myremote.jfrog.io/artifactory/api/conan/conan-local",
        "verify_ssl": true,
        "enabled": true
    },
    {
        "name": "conancenter",
        "url": "https://center.conan.io",
        "verify_ssl": true,
        "enabled": true
    }
]

Then you check the json, not string matching

Also if you want to not add a remote which URL already exist, Conan already protect against that:

 conan remote add -h
usage: conan remote add [-h] [-v [V]] [--logger] [--insecure] [--index INDEX] [-f] name url

Add a remote.

positional arguments:
  name           Name of the remote to add
  url            Url of the remote

optional arguments:
  -h, --help     show this help message and exit
  -v [V]         Level of detail of the output. Valid options from less verbose to more verbose: -vquiet, -verror, -vwarning, -vnotice, -vstatus, -v or
                 -vverbose, -vv or -vdebug, -vvv or -vtrace
  --logger       Show the output with log format, with time, type and message.
  --insecure     Allow insecure server connections when using SSL
  --index INDEX  Insert the remote at a specific position in the remote list
  -f, --force    Force the definition of the remote even if duplicated

It will error if the URL is repeated, unless you pass the --force argument. So no need to check it and do, you can just try-except it.

So it seems this very specific niche command would not be necessary. If you want to further automate some complex tasks, I'd recommend having a look to the custom commands: https://docs.conan.io/2/reference/extensions/custom_commands.html

szy1840 commented 1 year ago

Thank you for your reply, it's very helpful. But I still do need to check the url, because the Error output often make users feel puzzled, because they may have exactly the same name-url I want to add. Actually, maybe this behavior of conan(and other tools) is worth reconsidering. And Another problem is that I want to check if the user do have the remote-url in the remote list, it's possible that the user have the url under a different remote-name.

memsharded commented 1 year ago

If you need to check the URL in an automated way, still the conan remote list --format=json is the recommended way to go. Otherwise Conan would end with a cluttered CLI with conan remote get-verify-ssl, conan remote get-enabled, and this is not good UI/UX design.

In any case, adding remotes automatically is something that probably is not the most recommended way to do it. Instead, defining remotes.json file and managing it with conan config install is more useful, powerful and easier to manage and evolve if necessary.

szy1840 commented 1 year ago

Yes, I'd better move this config to remote.json