You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: client/v2/README.md
+43-39Lines changed: 43 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,9 @@
2
2
sidebar_position: 1
3
3
---
4
4
5
-
# AutoCLI
5
+
# Client/v2
6
+
7
+
## AutoCLI
6
8
7
9
:::note Synopsis
8
10
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
14
16
15
17
:::
16
18
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.
18
20
19
-
## Overview
21
+
###Overview
20
22
21
23
`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.
22
24
@@ -32,7 +34,7 @@ For instance, `autocli` would generate a command named `my-method` for the `MyMe
32
34
33
35
It is possible to customize the generation of transactions and queries by defining options for each service.
`autocli` uses a keyring for key name resolving names and signing transactions.
79
81
@@ -100,7 +102,7 @@ keyring.NewAutoCLIKeyring(kb)
100
102
101
103
:::
102
104
103
-
## Signing
105
+
###Signing
104
106
105
107
`autocli` supports signing transactions with the keyring.
106
108
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
110
112
AutoCLI currently supports only one signer per transaction.
111
113
:::
112
114
113
-
## Module wiring & Customization
115
+
###Module wiring & Customization
114
116
115
117
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.
116
118
@@ -131,31 +133,7 @@ AutoCLI can create a gov proposal of any tx by simply setting the `GovProposal`
131
133
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).
132
134
:::
133
135
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.
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.
161
139
@@ -165,7 +143,7 @@ This example shows how to use the `autocliv1.ServiceCommandDescriptor` struct to
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.
171
149
@@ -183,7 +161,7 @@ Then the command can be used as follows, instead of having to specify the `--add
183
161
<appd> query auth account cosmos1abcd...xyz
184
162
```
185
163
186
-
### Customising Flag Names
164
+
####Customising Flag Names
187
165
188
166
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.
189
167
@@ -200,7 +178,7 @@ autocliv1.RpcCommandOptions{
200
178
201
179
`FlagsOptions` is defined like sub commands in the `AutoCLIOptions()` method on your module.
202
180
203
-
### Combining AutoCLI with Other Commands Within A Module
181
+
####Combining AutoCLI with Other Commands Within A Module
204
182
205
183
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.
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).
214
192
215
-
### Skip a command
193
+
####Skip a command
216
194
217
195
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.
218
196
@@ -225,7 +203,7 @@ Additionally, a command can be manually skipped using the `autocliv1.RpcCommandO
225
203
}
226
204
```
227
205
228
-
### Use AutoCLI for non module commands
206
+
####Use AutoCLI for non module commands
229
207
230
208
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.
231
209
@@ -235,7 +213,31 @@ For example, here is how the SDK does it for `cometbft` gRPC commands:
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.
`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.
241
243
@@ -245,7 +247,7 @@ For more information on `hubl`, including how to configure a new chain and query
245
247
246
248
# Off-Chain
247
249
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:
249
251
250
252
*`sign-file` for signing a file.
251
253
*`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
Copy file name to clipboardExpand all lines: docs/build/tooling/00-protobuf.md
+9-28Lines changed: 9 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,21 +4,17 @@ sidebar_position: 1
4
4
5
5
# Protocol Buffers
6
6
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.
8
8
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`
10
10
11
11
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.
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.
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`).
40
38
41
39
```bash
42
40
├── README.md
@@ -50,8 +48,6 @@ Next is the `proto/` directory where all of our protobuf files live. In here the
50
48
└── tendermint
51
49
```
52
50
53
-
The above diagram all the files and directories within the Cosmos SDK `proto/` directory.
54
-
55
51
#### `buf.gen.gogo.yaml`
56
52
57
53
`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
Example of how to define `gen` files can be found [here](https://docs.buf.build/tour/generate-go-code)
65
-
:::
66
-
67
59
#### `buf.gen.pulsar.yaml`
68
60
69
61
`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/
Example of how to define `gen` files can be found [here](https://docs.buf.build/tour/generate-go-code)
77
-
:::
78
-
79
67
#### `buf.gen.swagger.yaml`
80
68
81
69
`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/
Example of how to define `gen` files can be found [here](https://docs.buf.build/tour/generate-go-code)
89
-
:::
90
-
91
75
#### `buf.lock`
92
76
93
77
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`.
`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).
102
86
87
+
It is advised to use a tagged version of the buf modules corresponding to the version of the Cosmos SDK being are used.
@@ -39,10 +39,10 @@ An implementation example can be found in `simapp`.
39
39
40
40
The command will be available as `simd config`.
41
41
42
-
```tip
42
+
:::tip
43
43
Using confix directly in the application can have less features than using it standalone.
44
44
This is because confix is versioned with the SDK, while `latest` is the standalone version.
45
-
```
45
+
:::
46
46
47
47
### Using Confix Standalone
48
48
@@ -138,7 +138,7 @@ confix view ~/.simapp/config/client.toml # views the current app client conf
138
138
139
139
### Maintainer
140
140
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`.
142
142
This allows users to use the tool standalone.
143
143
144
144
### Compatibility
@@ -149,7 +149,8 @@ The recommended standalone version is `latest`, which is using the latest develo
149
149
| ----------- | -------------- |
150
150
| v0.50 | v0.1.x |
151
151
| v0.52 | v0.2.x |
152
+
| v2 | v0.2.x |
152
153
153
154
## Credits
154
155
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