Skip to content

Commit e9486fc

Browse files
docs: tooling (backport #22049) (#22058)
Co-authored-by: Julien Robert <julien@rbrt.fr>
1 parent 96c62b0 commit e9486fc

File tree

5 files changed

+64
-78
lines changed

5 files changed

+64
-78
lines changed

client/v2/README.md

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
sidebar_position: 1
33
---
44

5-
# AutoCLI
5+
# Client/v2
6+
7+
## AutoCLI
68

79
:::note Synopsis
810
This document details how to build CLI and REST interfaces for a module. Examples from various Cosmos SDK modules are included.
@@ -14,9 +16,9 @@ This document details how to build CLI and REST interfaces for a module. Example
1416

1517
:::
1618

17-
The `autocli` (also known as `client/v2`) package is a [Go library](https://pkg.go.dev/cosmossdk.io/client/v2/autocli) for generating CLI (command line interface) interfaces for Cosmos SDK-based applications. It provides a simple way to add CLI commands to your application by generating them automatically based on your gRPC service definitions. Autocli generates CLI commands and flags directly from your protobuf messages, including options, input parameters, and output parameters. This means that you can easily add a CLI interface to your application without having to manually create and manage commands.
19+
The `autocli` (also known as `client/v2/autocli`) package is a [Go library](https://pkg.go.dev/cosmossdk.io/client/v2/autocli) for generating CLI (command line interface) interfaces for Cosmos SDK-based applications. It provides a simple way to add CLI commands to your application by generating them automatically based on your gRPC service definitions. Autocli generates CLI commands and flags directly from your protobuf messages, including options, input parameters, and output parameters. This means that you can easily add a CLI interface to your application without having to manually create and manage commands.
1820

19-
## Overview
21+
### Overview
2022

2123
`autocli` generates CLI commands and flags for each method defined in your gRPC service. By default, it generates commands for each gRPC services. The commands are named based on the name of the service method.
2224

@@ -32,7 +34,7 @@ For instance, `autocli` would generate a command named `my-method` for the `MyMe
3234

3335
It is possible to customize the generation of transactions and queries by defining options for each service.
3436

35-
## Application Wiring
37+
### Application Wiring
3638

3739
Here are the steps to use AutoCLI:
3840

@@ -73,7 +75,7 @@ if err := rootCmd.Execute(); err != nil {
7375
}
7476
```
7577

76-
### Keyring
78+
#### Keyring
7779

7880
`autocli` uses a keyring for key name resolving names and signing transactions.
7981

@@ -100,7 +102,7 @@ keyring.NewAutoCLIKeyring(kb)
100102

101103
:::
102104

103-
## Signing
105+
### Signing
104106

105107
`autocli` supports signing transactions with the keyring.
106108
The [`cosmos.msg.v1.signer` protobuf annotation](https://docs.cosmos.network/main/build/building-modules/protobuf-annotations) defines the signer field of the message.
@@ -110,7 +112,7 @@ This field is automatically filled when using the `--from` flag or defining the
110112
AutoCLI currently supports only one signer per transaction.
111113
:::
112114

113-
## Module wiring & Customization
115+
### Module wiring & Customization
114116

115117
The `AutoCLIOptions()` method on your module allows to specify custom commands, sub-commands or flags for each service, as it was a `cobra.Command` instance, within the `RpcCommandOptions` struct. Defining such options will customize the behavior of the `autocli` command generation, which by default generates a command for each method in your gRPC service.
116118

@@ -131,31 +133,7 @@ AutoCLI can create a gov proposal of any tx by simply setting the `GovProposal`
131133
Users can however use the `--no-proposal` flag to disable the proposal creation (which is useful if the authority isn't the gov module on a chain).
132134
:::
133135

134-
### Conventions for the `Use` field in Cobra
135-
136-
According to the [Cobra documentation](https://pkg.go.dev/github.com/spf13/cobra#Command) the following conventions should be followed for the `Use` field in Cobra commands:
137-
138-
1. **Required arguments**:
139-
* Should not be enclosed in brackets. They can be enclosed in angle brackets `< >` for clarity.
140-
* Example: `command <required_argument>`
141-
142-
2. **Optional arguments**:
143-
* Should be enclosed in square brackets `[ ]`.
144-
* Example: `command [optional_argument]`
145-
146-
3. **Alternative (mutually exclusive) arguments**:
147-
* Should be enclosed in curly braces `{ }`.
148-
* Example: `command {-a | -b}` for required alternatives.
149-
* Example: `command [-a | -b]` for optional alternatives.
150-
151-
4. **Multiple arguments**:
152-
* Indicated with `...` after the argument.
153-
* Example: `command argument...`
154-
155-
5. **Combination of options**:
156-
* Example: `command [-F file | -D dir]... [-f format] profile`
157-
158-
### Specifying Subcommands
136+
#### Specifying Subcommands
159137

160138
By default, `autocli` generates a command for each method in your gRPC service. However, you can specify subcommands to group related commands together. To specify subcommands, use the `autocliv1.ServiceCommandDescriptor` struct.
161139

@@ -165,7 +143,7 @@ This example shows how to use the `autocliv1.ServiceCommandDescriptor` struct to
165143
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-beta.0/x/gov/autocli.go#L94-L97
166144
```
167145

168-
### Positional Arguments
146+
#### Positional Arguments
169147

170148
By default `autocli` generates a flag for each field in your protobuf message. However, you can choose to use positional arguments instead of flags for certain fields.
171149

@@ -183,7 +161,7 @@ Then the command can be used as follows, instead of having to specify the `--add
183161
<appd> query auth account cosmos1abcd...xyz
184162
```
185163

186-
### Customising Flag Names
164+
#### Customising Flag Names
187165

188166
By default, `autocli` generates flag names based on the names of the fields in your protobuf message. However, you can customise the flag names by providing a `FlagOptions`. This parameter allows you to specify custom names for flags based on the names of the message fields.
189167

@@ -200,7 +178,7 @@ autocliv1.RpcCommandOptions{
200178

201179
`FlagsOptions` is defined like sub commands in the `AutoCLIOptions()` method on your module.
202180

203-
### Combining AutoCLI with Other Commands Within A Module
181+
#### Combining AutoCLI with Other Commands Within A Module
204182

205183
AutoCLI can be used alongside other commands within a module. For example, the `gov` module uses AutoCLI to generate commands for the `query` subcommand, but also defines custom commands for the `proposer` subcommands.
206184

@@ -212,7 +190,7 @@ https://github.com/cosmos/cosmos-sdk/blob/fa4d87ef7e6d87aaccc94c337ffd2fe90fcb7a
212190

213191
If not set to true, `AutoCLI` will not generate commands for the module if there are already commands registered for the module (when `GetTxCmd()` or `GetQueryCmd()` are defined).
214192

215-
### Skip a command
193+
#### Skip a command
216194

217195
AutoCLI automatically skips unsupported commands when [`cosmos_proto.method_added_in` protobuf annotation](https://docs.cosmos.network/main/build/building-modules/protobuf-annotations) is present.
218196

@@ -225,7 +203,7 @@ Additionally, a command can be manually skipped using the `autocliv1.RpcCommandO
225203
}
226204
```
227205

228-
### Use AutoCLI for non module commands
206+
#### Use AutoCLI for non module commands
229207

230208
It is possible to use `AutoCLI` for non module commands. The trick is still to implement the `appmodule.Module` interface and append it to the `appOptions.ModuleOptions` map.
231209

@@ -235,7 +213,31 @@ For example, here is how the SDK does it for `cometbft` gRPC commands:
235213
https://github.com/cosmos/cosmos-sdk/blob/main/client/grpc/cmtservice/autocli.go#L52-L71
236214
```
237215

238-
## Summary
216+
#### Conventions for the `Use` field in Cobra
217+
218+
According to the [Cobra documentation](https://pkg.go.dev/github.com/spf13/cobra#Command) the following conventions should be followed for the `Use` field in Cobra commands:
219+
220+
1. **Required arguments**:
221+
* Should not be enclosed in brackets. They can be enclosed in angle brackets `< >` for clarity.
222+
* Example: `command <required_argument>`
223+
224+
2. **Optional arguments**:
225+
* Should be enclosed in square brackets `[ ]`.
226+
* Example: `command [optional_argument]`
227+
228+
3. **Alternative (mutually exclusive) arguments**:
229+
* Should be enclosed in curly braces `{ }`.
230+
* Example: `command {-a | -b}` for required alternatives.
231+
* Example: `command [-a | -b]` for optional alternatives.
232+
233+
4. **Multiple arguments**:
234+
* Indicated with `...` after the argument.
235+
* Example: `command argument...`
236+
237+
5. **Combination of options**:
238+
* Example: `command [-F file | -D dir]... [-f format] profile`
239+
240+
### Summary
239241

240242
`autocli` lets you generate CLI to your Cosmos SDK-based applications without any cobra boilerplate. It allows you to easily generate CLI commands and flags from your protobuf messages, and provides many options for customising the behavior of your CLI application.
241243

@@ -245,7 +247,7 @@ For more information on `hubl`, including how to configure a new chain and query
245247

246248
# Off-Chain
247249

248-
Off-chain functionalities allow you to sign and verify files with two commands:
250+
Off-chain is a `client/v2` package providing functionalities for allowing to sign and verify files with two commands:
249251

250252
* `sign-file` for signing a file.
251253
* `verify-file` for verifying a previously signed file.
@@ -275,6 +277,7 @@ The `encoding` flag lets you choose how the contents of the file should be encod
275277
"signer": "cosmos1x33fy6rusfprkntvjsfregss7rvsvyy4lkwrqu",
276278
"data": "Hello World!\n"
277279
}
280+
278281
```
279282

280283
* `simd off-chain sign-file alice myFile.json --encoding base64`
@@ -286,6 +289,7 @@ The `encoding` flag lets you choose how the contents of the file should be encod
286289
"signer": "cosmos1x33fy6rusfprkntvjsfregss7rvsvyy4lkwrqu",
287290
"data": "SGVsbG8gV29ybGQhCg=="
288291
}
292+
289293
```
290294

291295
* `simd off-chain sign-file alice myFile.json --encoding hex`

docs/build/tooling/00-protobuf.md

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,17 @@ sidebar_position: 1
44

55
# Protocol Buffers
66

7-
It is known that Cosmos SDK uses protocol buffers extensively, this document is meant to provide a guide on how it is used in the cosmos-sdk.
7+
Cosmos SDK uses protocol buffers extensively, this document is meant to provide a guide on how it is used in the cosmos-sdk.
88

9-
To generate the proto file, the Cosmos SDK uses a docker image, this image is provided to all to use as well. The latest version is `ghcr.io/cosmos/proto-builder:0.12.x`
9+
To generate the proto file, the Cosmos SDK uses a docker image, this image is provided to all to use as well. The latest version is `ghcr.io/cosmos/proto-builder:0.15.x`
1010

1111
Below is the example of the Cosmos SDK's commands for generating, linting, and formatting protobuf files that can be reused in any applications makefile.
1212

1313
```go reference
14-
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/Makefile#L411-L432
14+
https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/scripts/build/protobuf.mk#L1-L10
1515
```
1616

17-
The script used to generate the protobuf files can be found in the `scripts/` directory.
18-
19-
```shell reference
20-
https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/scripts/protocgen.sh
21-
```
17+
The [`protocgen.sh`](https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/scripts/protocgen.sh) script used to generate the protobuf files via buf can be found in the `scripts/` directory.
2218

2319
## Buf
2420

@@ -36,7 +32,9 @@ https://github.com/cosmos/cosmos-sdk/blob/main/buf.work.yaml#L6-L9
3632

3733
### Proto Directory
3834

39-
Next is the `proto/` directory where all of our protobuf files live. In here there are many different buf files defined each serving a different purpose.
35+
The `proto/` directory where all of global protobuf files live.
36+
In here there are many different buf files defined each serving a different purpose.
37+
Modules proto files are defined in their respective module directories (in the SDK `x/{moduleName}/proto`).
4038

4139
```bash
4240
├── README.md
@@ -50,8 +48,6 @@ Next is the `proto/` directory where all of our protobuf files live. In here the
5048
└── tendermint
5149
```
5250

53-
The above diagram all the files and directories within the Cosmos SDK `proto/` directory.
54-
5551
#### `buf.gen.gogo.yaml`
5652

5753
`buf.gen.gogo.yaml` defines how the protobuf files should be generated for use with in the module. This file uses [gogoproto](https://github.com/gogo/protobuf), a separate generator from the google go-proto generator that makes working with various objects more ergonomic, and it has more performant encode and decode steps
@@ -60,10 +56,6 @@ The above diagram all the files and directories within the Cosmos SDK `proto/` d
6056
https://github.com/cosmos/cosmos-sdk/blob/main/proto/buf.gen.gogo.yaml#L1-L9
6157
```
6258

63-
:::tip
64-
Example of how to define `gen` files can be found [here](https://docs.buf.build/tour/generate-go-code)
65-
:::
66-
6759
#### `buf.gen.pulsar.yaml`
6860

6961
`buf.gen.pulsar.yaml` defines how protobuf files should be generated using the [new golang apiv2 of protobuf](https://go.dev/blog/protobuf-apiv2). This generator is used instead of the google go-proto generator because it has some extra helpers for Cosmos SDK applications and will have more performant encode and decode than the google go-proto generator. You can follow the development of this generator [here](https://github.com/cosmos/cosmos-proto).
@@ -72,10 +64,6 @@ Example of how to define `gen` files can be found [here](https://docs.buf.build/
7264
https://github.com/cosmos/cosmos-sdk/blob/main/proto/buf.gen.pulsar.yaml#L1-L18
7365
```
7466

75-
:::tip
76-
Example of how to define `gen` files can be found [here](https://docs.buf.build/tour/generate-go-code)
77-
:::
78-
7967
#### `buf.gen.swagger.yaml`
8068

8169
`buf.gen.swagger.yaml` generates the swagger documentation for the query and messages of the chain. This will only define the REST API end points that were defined in the query and msg servers. You can find examples of this [here](https://github.com/cosmos/cosmos-sdk/blob/main/x/bank/proto/cosmos/bank/v1beta1/query.proto)
@@ -84,10 +72,6 @@ Example of how to define `gen` files can be found [here](https://docs.buf.build/
8472
https://github.com/cosmos/cosmos-sdk/blob/main/proto/buf.gen.swagger.yaml#L1-L6
8573
```
8674

87-
:::tip
88-
Example of how to define `gen` files can be found [here](https://docs.buf.build/tour/generate-go-code)
89-
:::
90-
9175
#### `buf.lock`
9276

9377
This is an autogenerated file based off the dependencies required by the `.gen` files. There is no need to copy the current one. If you depend on cosmos-sdk proto definitions a new entry for the Cosmos SDK will need to be provided. The dependency you will need to use is `buf.build/cosmos/cosmos-sdk`.
@@ -100,14 +84,11 @@ https://github.com/cosmos/cosmos-sdk/blob/main/proto/buf.lock#L1-L16
10084

10185
`buf.yaml` defines the [name of your package](https://github.com/cosmos/cosmos-sdk/blob/main/proto/buf.yaml#L3), which [breakage checker](https://buf.build/docs/tutorials/getting-started-with-buf-cli#detect-breaking-changes) to use and how to [lint your protobuf files](https://buf.build/docs/tutorials/getting-started-with-buf-cli#lint-your-api).
10286

87+
It is advised to use a tagged version of the buf modules corresponding to the version of the Cosmos SDK being are used.
88+
10389
```go reference
10490
https://github.com/cosmos/cosmos-sdk/blob/main/proto/buf.yaml#L1-L24
10591
```
10692

10793
We use a variety of linters for the Cosmos SDK protobuf files. The repo also checks this in ci.
108-
10994
A reference to the github actions can be found [here](https://github.com/cosmos/cosmos-sdk/blob/main/.github/workflows/proto.yml#L1-L32)
110-
111-
```go reference
112-
https://github.com/cosmos/cosmos-sdk/blob/main/.github/workflows/proto.yml#L1-L32
113-
```

simapp/upgrades.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import (
1515
)
1616

1717
// UpgradeName defines the on-chain upgrade name for the sample SimApp upgrade
18-
// from v0.50.x to v0.51.x
18+
// from v0.50.x to v0.52.x
1919
//
2020
// NOTE: This upgrade defines a reference implementation of what an upgrade
2121
// could look like when an application is migrating from Cosmos SDK version
22-
// v0.50.x to v0.51.x.
23-
const UpgradeName = "v050-to-v051"
22+
// v0.59.x to v0.52.x.
23+
const UpgradeName = "v050-to-v052"
2424

2525
func (app SimApp) RegisterUpgradeHandlers() {
2626
app.UpgradeKeeper.SetUpgradeHandler(

simapp/v2/upgrades.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import (
1212
)
1313

1414
// UpgradeName defines the on-chain upgrade name for the sample SimApp upgrade
15-
// from v0.50.x to v0.51.x
15+
// from v0.50.x to v2
1616
//
1717
// NOTE: This upgrade defines a reference implementation of what an upgrade
1818
// could look like when an application is migrating from Cosmos SDK version
19-
// v0.50.x to v0.51.x.
20-
const UpgradeName = "v050-to-v051"
19+
// v0.50.x to v2.
20+
const UpgradeName = "v050-to-v2"
2121

2222
func (app *SimApp[T]) RegisterUpgradeHandlers() {
2323
app.UpgradeKeeper.SetUpgradeHandler(

tools/confix/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import "cosmossdk.io/tools/confix/cmd"
2323
Find the following line:
2424

2525
```go
26-
initRootCmd(rootCmd, encodingConfig)
26+
initRootCmd(rootCmd, moduleManager)
2727
```
2828

2929
After that line, add the following:
@@ -39,10 +39,10 @@ An implementation example can be found in `simapp`.
3939

4040
The command will be available as `simd config`.
4141

42-
```tip
42+
:::tip
4343
Using confix directly in the application can have less features than using it standalone.
4444
This is because confix is versioned with the SDK, while `latest` is the standalone version.
45-
```
45+
:::
4646

4747
### Using Confix Standalone
4848

@@ -138,7 +138,7 @@ confix view ~/.simapp/config/client.toml # views the current app client conf
138138

139139
### Maintainer
140140

141-
At each SDK modification of the default configuration, add the default SDK config under `data/v0.XX-app.toml`.
141+
At each SDK modification of the default configuration, add the default SDK config under `data/vXX-app.toml`.
142142
This allows users to use the tool standalone.
143143

144144
### Compatibility
@@ -149,7 +149,8 @@ The recommended standalone version is `latest`, which is using the latest develo
149149
| ----------- | -------------- |
150150
| v0.50 | v0.1.x |
151151
| v0.52 | v0.2.x |
152+
| v2 | v0.2.x |
152153

153154
## Credits
154155

155-
This project is based on the [CometBFT RFC 019](https://github.com/cometbft/cometbft/blob/5013bc3f4a6d64dcc2bf02ccc002ebc9881c62e4/docs/rfc/rfc-019-config-version.md) and their own implementation of [confix](https://github.com/cometbft/cometbft/blob/v0.36.x/scripts/confix/confix.go).
156+
This project is based on the [CometBFT RFC 019](https://github.com/cometbft/cometbft/blob/5013bc3f4a6d64dcc2bf02ccc002ebc9881c62e4/docs/rfc/rfc-019-config-version.md) and their never released own implementation of [confix](https://github.com/cometbft/cometbft/blob/v0.36.x/scripts/confix/confix.go).

0 commit comments

Comments
 (0)