Confix 是一个配置管理工具,可让你通过 CLI 管理配置。 它基于 CometBFT RFC 019。

安装

添加 Config 命令

要添加 confix 工具,需要在应用的根命令文件中(例如 <appd>/cmd/root.go)加入 ConfigCommand。 导入 confixCmd 包:
import confixcmd "cosmossdk.io/tools/confix/cmd"
在 initRootCmd 函数中,将该命令添加到根命令:
rootCmd.AddCommand(
    confixcmd.ConfigCommand(),
)
ConfigCommand 函数会构建 config 根命令,它定义在 confixcmd 包(cosmossdk.io/tools/confix/cmd)中。 你可以在 simapp 中找到一个实现示例。 该命令将以 simd config 的形式提供。
直接在应用中使用 confix,其功能可能少于独立使用时的功能。 这是因为 confix 会随 SDK 版本发布,而 latest 是独立发布的版本。

独立使用 Confix

如果你希望独立使用 Confix,而无需将其添加到应用中,可通过以下命令安装:
go install cosmossdk.io/tools/confix/cmd/confix@latest
或者,如果你希望从源码构建,只需运行 make confix。生成的二进制文件位于 tools/confix。

用法

独立使用:
confix --help
在 simd 中使用:
simd config --help

Get

获取某个配置值,例如:
simd config get app pruning # gets the value pruning from app.toml
simd config get client chain-id # gets the value chain-id from client.toml
confix get ~/.simapp/config/app.toml pruning # gets the value pruning from app.toml
confix get ~/.simapp/config/client.toml chain-id # gets the value chain-id from client.toml

Set

设置某个配置值,例如:
simd config set app pruning "enabled" # sets the value pruning from app.toml
simd config set client chain-id "foo-1" # sets the value chain-id from client.toml
confix set ~/.simapp/config/app.toml pruning "enabled" # sets the value pruning from app.toml
confix set ~/.simapp/config/client.toml chain-id "foo-1" # sets the value chain-id from client.toml

Migrate

将配置文件迁移到新版本。配置类型默认为 app.toml;如果你想改为 client.toml,请通过添加可选参数进行指定,例如:
simd config migrate v0.53 # migrates defaultHome/config/app.toml to the latest v0.53 config
simd config migrate v0.53 --client # migrates defaultHome/config/client.toml to the latest v0.53 config
confix migrate v0.53 ~/.simapp/config/app.toml # migrate ~/.simapp/config/app.toml to the latest v0.53 config
confix migrate v0.53 ~/.simapp/config/client.toml --client # migrate ~/.simapp/config/client.toml to the latest v0.53 config

Diff

获取给定配置文件与默认配置文件之间的差异,例如:
simd config diff v0.53 # gets the diff between defaultHome/config/app.toml and the latest v0.53 config
simd config diff v0.53 --client # gets the diff between defaultHome/config/client.toml and the latest v0.53 config
confix diff v0.53 ~/.simapp/config/app.toml # gets the diff between ~/.simapp/config/app.toml and the latest v0.53 config
confix diff v0.53 ~/.simapp/config/client.toml --client # gets the diff between ~/.simapp/config/client.toml and the latest v0.53 config

View

查看配置文件,例如:
simd config view client # views the current app client config
confix view ~/.simapp/config/client.toml # views the current app client config

维护者

每当 SDK 的默认配置发生修改时,请将默认 SDK 配置添加到 data/vXX-app.toml。 这样用户才能独立使用该工具。

致谢

本项目基于 CometBFT RFC 019 以及他们从未正式发布的 confix 实现。
Confix is a configuration management tool that allows you to manage your configuration via CLI. It is based on the CometBFT RFC 019.

Installation

Add Config Command

To add the confix tool, it’s required to add the ConfigCommand to your application’s root command file (e.g. <appd>/cmd/root.go). Import the confixCmd package:
import confixcmd "cosmossdk.io/tools/confix/cmd"
Inside your initRootCmd function, add the command to the root:
rootCmd.AddCommand(
    confixcmd.ConfigCommand(),
)
The ConfigCommand function builds the config root command and is defined in the confixcmd package (cosmossdk.io/tools/confix/cmd). An implementation example can be found in simapp. The command will be available as simd config.
Using confix directly in the application can have less features than using it standalone. This is because confix is versioned with the SDK, while latest is the standalone version.

Using Confix Standalone

To use Confix standalone, without having to add it in your application, install it with the following command:
go install cosmossdk.io/tools/confix/cmd/confix@latest
Alternatively, for building from source, simply run make confix. The binary will be located in tools/confix.

Usage

Use standalone:
confix --help
Use in simd:
simd config --help

Get

Get a configuration value, e.g.:
simd config get app pruning # gets the value pruning from app.toml
simd config get client chain-id # gets the value chain-id from client.toml
confix get ~/.simapp/config/app.toml pruning # gets the value pruning from app.toml
confix get ~/.simapp/config/client.toml chain-id # gets the value chain-id from client.toml

Set

Set a configuration value, e.g.:
simd config set app pruning "enabled" # sets the value pruning from app.toml
simd config set client chain-id "foo-1" # sets the value chain-id from client.toml
confix set ~/.simapp/config/app.toml pruning "enabled" # sets the value pruning from app.toml
confix set ~/.simapp/config/client.toml chain-id "foo-1" # sets the value chain-id from client.toml

Migrate

Migrate a configuration file to a new version, config type defaults to app.toml, if you want to change it to client.toml, please indicate it by adding the optional parameter, e.g.:
simd config migrate v0.53 # migrates defaultHome/config/app.toml to the latest v0.53 config
simd config migrate v0.53 --client # migrates defaultHome/config/client.toml to the latest v0.53 config
confix migrate v0.53 ~/.simapp/config/app.toml # migrate ~/.simapp/config/app.toml to the latest v0.53 config
confix migrate v0.53 ~/.simapp/config/client.toml --client # migrate ~/.simapp/config/client.toml to the latest v0.53 config

Diff

Get the diff between a given configuration file and the default configuration file, e.g.:
simd config diff v0.53 # gets the diff between defaultHome/config/app.toml and the latest v0.53 config
simd config diff v0.53 --client # gets the diff between defaultHome/config/client.toml and the latest v0.53 config
confix diff v0.53 ~/.simapp/config/app.toml # gets the diff between ~/.simapp/config/app.toml and the latest v0.53 config
confix diff v0.53 ~/.simapp/config/client.toml --client # gets the diff between ~/.simapp/config/client.toml and the latest v0.53 config

View

View a configuration file, e.g:
simd config view client # views the current app client config
confix view ~/.simapp/config/client.toml # views the current app client config

Maintainer

At each SDK modification of the default configuration, add the default SDK config under data/vXX-app.toml. This allows users to use the tool standalone.

Credits

This project is based on the CometBFT RFC 019 and their never released own implementation of confix.