本文档翻译自:https://docs.conan.io/en/latest/reference/commands/consumer/config.html
$ conan config [-h] {get,home,install,rm,set} ...
管理Conan配置。
用于编辑conan.conf或安装 config 文件。
positional arguments:
{get,home,install,rm,set}
sub-command help
get 获取配置项的值
home 检索conan主目录
install 从本地或远程zip文件安装完整配置
rm 删除现有的配置元素
set 设置配置项的值
init 初始化conan配置文件
optional arguments:
-h, --help show this help message and exit
Examples
将日志记录级别更改为10:
$ conan config set log.level=10
获取日志记录级别:
$ conan config get log.level
$> 10
获取Conan home目录:
$ conan config home
$> /home/user/.conan
创建所有丢失的配置文件:
$ conan config init
删除现有的配置文件并创建所有配置文件:
$ conan config init --force
conan config install
```shell usage: conan config install [-h] [—verify-ssl [VERIFY_SSL]] [—type {git}]
[--args ARGS] [-sf SOURCE_FOLDER] [-tf TARGET_FOLDER]
[-l] [-r REMOVE]
[item]
positional arguments: item git存储库,本地文件夹或存储配置的zip文件(本地或http)
optional arguments: -h, —help show this help message and exit —verify-ssl [VERIFY_SSL] Verify SSL connection when downloading file —type {git}, -t {git} Type of remote config —args ARGS, -a ARGS 带有 “git clone” 额外参数的字符串 -sf SOURCE_FOLDER, —source-folder SOURCE_FOLDER 仅从指定来源的源子文件夹安装文件 -tf TARGET_FOLDER, —target-folder TARGET_FOLDER 安装到conan缓存中的该路径 -l, —list List stored configuration origins -r REMOVE, —remove REMOVE Remove configuration origin by index in list (index provided by —list argument)
`config install`旨在共享Conan客户端配置。 例如,在公司或组织中,具有通用(`settings.yml`,`profiles `等)很重要。<br />它可以从本地或远程zip文件,本地目录或git存储库中获取其配置文件。 然后,将文件安装在本地Conan配置中。<br />该配置可以包含全部或部分允许的配置文件。 仅存在的文件将被替换。 唯一的例外是conan.conf文件,仅会为其安装声明的变量,而其他变量保持不变。<br />这意味着,例如,**profiles**和**hooks**文件(如果已存在)将被覆盖,但是不会删除用户在本地计算机中拥有的概要文件或挂钩文件。<br />所有配置文件都将复制到Conan主目录。 这些是特殊文件以及用于合并它们的规则:
| 文件 | **如何运用** |
| --- | --- |
| profiles/MyProfile | 覆盖本地~/.conan/profiles/MyProfile(如果已存在) |
| settings.yml | 覆盖本地~/.conan/settings.yml |
| remotes.txt | 覆盖remotes。 将删除文件中不存在的remotes |
| config/conan.conf | 合并变量,仅覆盖声明的变量 |
| hooks/my_hook.py | 覆盖本地~/.conan/hooks/my_hook.py(如果已存在) |
文件remotes.txt是上面列出的唯一文件,在**~/.conan**文件夹中没有直接对应的文件。 它的格式是条目列表,每行一个,格式为
```shell
[remote name] [remote url] [bool]
其中[bool]
(True
或False
)指示是否应使用SSL来验证该远程服务器。 远程定义可以在remotes.json文件中找到,并且在编写要打包在Conan客户端配置中的remotes.txt时提供了一个有用的起点。
:::info
Note
在安装过程中,Conan会跳过任何名称为README.md或LICENSE.txt的文件。
:::
conan config install <item>
调用存储在Conan本地缓存中的config_install.json文件中。 这样就可以发出不带参数的conan config install
命令,以遍历缓存的配置,然后再次执行它们(更新)。
当在conan.conf中配置config_install_interval时,可以在执行任何命令之前定期执行conan config install
。 Conan基于config_install.json运行它,包括最后一次更改的时间戳。
Examples:
从URL安装配置:
$ conan config install http://url/to/some/config.zip
从URL安装配置,但只能将文件放在zip文件的原始文件夹中,并将它们放在本地缓存中的目标文件夹中:
$ conan config install http://url/to/some/config.zip -sf=origin -tf=target
使用来自2个不同url的2个不同zip文件安装配置,每个配置使用不同的源文件夹和目标文件夹,然后全部更新:
$ conan config install http://url/to/some/config.zip -sf=origin -tf=target
$ conan config install http://url/to/some/config.zip -sf=origin2 -tf=target2
$ conan config install http://other/url/to/other.zip -sf=hooks -tf=hooks
# Later on, execute again the previous configurations cached:
$ conan config install
无需指定任何参数,它将迭代config_install.json中先前存储的配置,并再次执行它们。
使用子模块从Git存储库安装配置:
$ conan config install http://github.com/user/conan_config/.git --args "--recursive"
您也可以使用—type git来强制git下载(以防不自动从URL推导出来):
$ conan config install http://github.com/user/conan_config/.git --type git
从URL安装跳过SSL验证:
$ conan config install http://url/to/some/config.zip --verify-ssl=False
这将禁用证书的SSL检查。
从本地路径安装配置:
$ conan config install /path/to/some/config.zip
列出所有以前安装的来源(如果在不使用args的情况下调用conan config install将使用的来源):
$ conan config install --list
这将显示存储的原点列表,其索引在列表内。
删除以前安装的来源之一:
$ conan config install --remove=1
这将删除现有原点的index = 1(列表中的第二个元素)的元素。 这意味着下一次 conan config install
手册或对此命令的计划调用将不再使用此来源。