Skip to content

Commit c6c9281

Browse files
authoredMay 13, 2022
feat: improve command readability (#12)
* add helper function to change output command syntax * rename contractAddress for address in wasm usage * add helper function to keys networks and wasm * update readme output * add getVersion util in order to use package json version * bump 0.1.6 version
1 parent 3620baf commit c6c9281

File tree

10 files changed

+56
-26
lines changed

10 files changed

+56
-26
lines changed
 

‎README.md

+10-14
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ Commands:
2828
keys [command] manage your keys
2929
networks [command] manage networks
3030
wasm [command] wasm transaction subcommands
31-
help [command] display help for command
3231
```
3332

3433
> **Wasm Command**
@@ -39,14 +38,13 @@ Usage: cwcli wasm [command]
3938
Wasm transaction subcommands
4039

4140
Options:
42-
-h, --help display help for command
41+
-h, --help display help for command
4342

4443
Commands:
45-
upload [options] <wasm file> Upload a wasm binary
46-
query [options] <contractAddress> <msg> Querying commands for contracts
47-
execute [options] <contractAddress> <msg> execute a smart contract method
48-
instantiate [options] <codeId> <msg> instantiate an uploaded contract
49-
help [command] display help for command
44+
upload <wasm file> Upload a wasm binary
45+
query <address> <msg> Querying commands for contracts
46+
execute <address> <msg> execute a smart contract method
47+
instantiate <codeId> <msg> instantiate an uploaded contract
5048
```
5149

5250
> **Keys Command**
@@ -57,14 +55,13 @@ Usage: cwcli keys [command]
5755
Manage your keys
5856

5957
Options:
60-
-h, --help display help for command
58+
-h, --help display help for command
6159

6260
Commands:
63-
add <name> Add an encrypted private key (either newly generated or recovered), encrypt it, and save to keyring
64-
delete <name> Delete keys from the cli
65-
show [options] <name> Return address depending on network selection
66-
list Return a list of all public keys stored by this cli
67-
help [command] display help for command display help for command
61+
add <name> Add an encrypted private key (either newly generated or recovered), encrypt it, and save to keyring
62+
delete <name> Delete keys from the cli
63+
show <name> Return address depending on network selection
64+
list Return a list of all public keys stored by this cli
6865
```
6966

7067
> **Network Command**
@@ -81,7 +78,6 @@ Commands:
8178
add <filePath> Load a custom network
8279
delete <name> Remove a custom network
8380
list show a list of networks
84-
help [command] display help for command
8581
```
8682

8783

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cosmwasm-cli",
3-
"version": "0.1.5",
3+
"version": "0.1.6",
44
"author": "Javier Aceña <j0nl1>",
55
"description": "Cosmwasm Command Line Interface",
66
"scripts": {

‎src/cli.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import { Command } from "commander";
22
import KeysCommand from "./commands/keys";
33
import NetworkCommand from "./commands/networks";
44
import WasmCommand from "./commands/wasm";
5+
import getVersion from "./utils/getVersion";
56

67
export default new Command("cwcli")
7-
.version("0.1.5")
8+
.version(getVersion())
89
.description("Cosmwasm Command Line Interface")
910
.usage("[command]")
1011
.addCommand(KeysCommand)
1112
.addCommand(NetworkCommand)
1213
.addCommand(WasmCommand)
14+
.addHelpCommand(false)
1315
.parse(process.argv);

‎src/commands/keys/index.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ import AddKeyCommand from "./addKey";
44
import ShowKeyCommand from "./showKey";
55
import DeleteKeyCommand from "./deleteKey";
66
import ListKeysCommand from "./listKeys";
7+
import subcommandTerm from "../../utils/subcommandTerm";
78

8-
export default new Command("keys")
9+
const KeysCommand = new Command("keys")
910
.description("Manage your keys")
1011
.usage("[command]")
1112
.addCommand(AddKeyCommand)
1213
.addCommand(DeleteKeyCommand)
1314
.addCommand(ShowKeyCommand)
1415
.addCommand(ListKeysCommand);
16+
17+
KeysCommand.addHelpCommand(false).configureHelp({ subcommandTerm });
18+
19+
export default KeysCommand;

‎src/commands/networks/index.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ import { Command } from "commander";
22
import AddCustomNetwork from "./addCustomNetwork";
33
import ListNetworkCommand from "./listNetworks";
44
import deleteCustomNetwork from "./deleteCustomNetwork";
5+
import subcommandTerm from "../../utils/subcommandTerm";
56

6-
export default new Command("networks")
7+
const NetworksCommand = new Command("networks")
78
.description("Manage networks")
89
.usage("[command]")
910
.addCommand(AddCustomNetwork)
1011
.addCommand(deleteCustomNetwork)
1112
.addCommand(ListNetworkCommand);
13+
14+
NetworksCommand.addHelpCommand(false).configureHelp({ subcommandTerm });
15+
16+
export default NetworksCommand;

‎src/commands/wasm/execute.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import NetworkOption from "../options/network";
55

66
export default new Command("execute")
77
.description("execute a smart contract method")
8-
.usage("<contractAddress> <msg> --address <name> --network <name> [options]")
9-
.argument("<contractAddress>")
8+
.usage("<address> <msg> --address <name> --network <name> [options]")
9+
.argument("<address>")
1010
.argument("<msg>")
1111
.addOption(AddressOption)
1212
.addOption(NetworkOption)

‎src/commands/wasm/index.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
import { Command } from "commander";
1+
import { Command, Help } from "commander";
22
import UploadCommand from "./upload";
33
import InstantiateCommand from "./instantiate";
44
import QueryCommand from "./query";
55
import ExecuteCommand from "./execute";
6+
import subcommandTerm from "../../utils/subcommandTerm";
67

7-
export default new Command("wasm")
8+
const t = new Help();
9+
10+
const WasmCommand = new Command("wasm")
811
.description("Wasm transaction subcommands")
912
.usage("[command]")
10-
.argument("[command]")
1113
.addCommand(UploadCommand)
1214
.addCommand(QueryCommand)
1315
.addCommand(ExecuteCommand)
1416
.addCommand(InstantiateCommand);
17+
18+
WasmCommand.addHelpCommand(false).configureHelp({ subcommandTerm });
19+
20+
export default WasmCommand;

‎src/commands/wasm/query.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { Command } from "commander";
1+
import { Command, Help } from "commander";
22
import { queryContract } from "../../services/wasm.service";
33
import NetworkOption from "../options/network";
44

55
export default new Command("query")
66
.description("Querying commands for contracts")
7-
.usage("<contractAddress> <msg> [options]")
8-
.argument("<contractAddress>")
7+
.usage("<address> <msg> [options]")
8+
.argument("<address>")
99
.argument("<msg>")
1010
.addOption(NetworkOption)
1111
.action(queryContract);

‎src/utils/getVersion.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import fs from "fs";
2+
import path from "path";
3+
4+
export default () => JSON.parse(fs.readFileSync(path.join(__dirname, "..", "..", "package.json"), "utf8")).version;

‎src/utils/subcommandTerm.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Argument, Command } from "commander";
2+
3+
export default (cmd: Command & { _name: string; _aliases: string[]; _args: Argument[] }) => {
4+
const args = cmd._args
5+
.map((arg: Argument) => {
6+
const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
7+
8+
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
9+
})
10+
.join(" ");
11+
return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (args ? " " + args : "");
12+
};

0 commit comments

Comments
 (0)
Please sign in to comment.