From 70e51211859425652c280ebf958c61b95a75f9ec Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Tue, 19 Dec 2023 19:09:57 -0500 Subject: [PATCH 1/3] style(golang): Align CLI command fields with upstream recommendations cf. https://pkg.go.dev/github.com/spf13/cobra#Command and https://github.com/spf13/cobra/blob/v1.8.0/site/content/user_guide.md#example Only optional arguments should be wrapped in square brackets, alternatives should be wrapped in curly braces, and `Long` strings should generally start similar to `Use`. --- golang/cosmos/daemon/cmd/genaccounts.go | 10 ++++---- golang/cosmos/daemon/cmd/testnet.go | 4 ++-- golang/cosmos/x/swingset/client/cli/query.go | 4 ++-- golang/cosmos/x/swingset/client/cli/tx.go | 25 ++++++++++++++------ golang/cosmos/x/vstorage/client/cli/query.go | 14 +++++++---- 5 files changed, 36 insertions(+), 21 deletions(-) diff --git a/golang/cosmos/daemon/cmd/genaccounts.go b/golang/cosmos/daemon/cmd/genaccounts.go index 8f05acd417c..242ddec24d3 100644 --- a/golang/cosmos/daemon/cmd/genaccounts.go +++ b/golang/cosmos/daemon/cmd/genaccounts.go @@ -30,12 +30,12 @@ const ( // AddGenesisAccountCmd returns add-genesis-account cobra Command. func AddGenesisAccountCmd(cdc codec.Codec, defaultNodeHome string) *cobra.Command { cmd := &cobra.Command{ - Use: "add-genesis-account [address_or_key_name] [coin][,[coin]]", + Use: "add-genesis-account [,...]", Short: "Add a genesis account to genesis.json", - Long: `Add a genesis account to genesis.json. The provided account must specify -the account address or key name and a list of initial coins. If a key name is given, -the address will be looked up in the local Keybase. The list of initial tokens must -contain valid denominations. Accounts may optionally be supplied with vesting parameters. + Long: `Add a genesis account to genesis.json. +If the address is specified by name, it will be looked up in the local Keybase. +The comma-separated list of initial tokens must contain valid denominations. +Accounts may optionally be supplied with vesting parameters. `, Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { diff --git a/golang/cosmos/daemon/cmd/testnet.go b/golang/cosmos/daemon/cmd/testnet.go index 0f8a5e697c6..96aec369160 100644 --- a/golang/cosmos/daemon/cmd/testnet.go +++ b/golang/cosmos/daemon/cmd/testnet.go @@ -48,7 +48,7 @@ func testnetCmd(mbm module.BasicManager, genBalIterator banktypes.GenesisBalance cmd := &cobra.Command{ Use: "testnet", Short: fmt.Sprintf("Initialize files for a %s testnet", AppName), - Long: `testnet will create "v" number of directories and populate each with + Long: `testnet will create one directory per validator and populate each with necessary files (private validator, genesis, config, etc.). Note, strict routability for addresses is turned off in the config file. @@ -83,7 +83,7 @@ Example: cmd.Flags().Int(flagNumValidators, 4, "Number of validators to initialize the testnet with") cmd.Flags().StringP(flagOutputDir, "o", "./mytestnet", "Directory to store initialization data for the testnet") - cmd.Flags().String(flagNodeDirPrefix, "node", "Prefix the directory name for each node with (node results in node0, node1, ...)") + cmd.Flags().String(flagNodeDirPrefix, "node", "Prefix for the name of per-validator subdirectories (to be number-suffixed like node0, node1, ...)") cmd.Flags().String(flagNodeDaemonHome, AppName, "Home directory of the node's daemon configuration") cmd.Flags().String(flagStartingIPAddress, "192.168.0.1", "Starting IP address (192.168.0.1 results in persistent peers list ID0@192.168.0.1:46656, ID1@192.168.0.2:46656, ...)") cmd.Flags().String(flags.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created") diff --git a/golang/cosmos/x/swingset/client/cli/query.go b/golang/cosmos/x/swingset/client/cli/query.go index 95f3b07a766..6fc7320e7fb 100644 --- a/golang/cosmos/x/swingset/client/cli/query.go +++ b/golang/cosmos/x/swingset/client/cli/query.go @@ -53,7 +53,7 @@ func GetCmdQueryParams(queryRoute string) *cobra.Command { func GetCmdGetEgress(queryRoute string) *cobra.Command { cmd := &cobra.Command{ - Use: "egress [account]", + Use: "egress ", Short: "get egress info for account", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { @@ -86,7 +86,7 @@ func GetCmdGetEgress(queryRoute string) *cobra.Command { // GetCmdMailbox queries information about a mailbox func GetCmdMailbox(queryRoute string) *cobra.Command { cmd := &cobra.Command{ - Use: "mailbox [peer]", + Use: "mailbox ", Short: "get mailbox for peer", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { diff --git a/golang/cosmos/x/swingset/client/cli/tx.go b/golang/cosmos/x/swingset/client/cli/tx.go index 2ea398a578f..b6d2f7ee34b 100644 --- a/golang/cosmos/x/swingset/client/cli/tx.go +++ b/golang/cosmos/x/swingset/client/cli/tx.go @@ -44,11 +44,16 @@ func GetTxCmd(storeKey string) *cobra.Command { } // GetCmdDeliver is the CLI command for sending a DeliverInbound transaction +// containing mailbox messages. func GetCmdDeliver() *cobra.Command { cmd := &cobra.Command{ - Use: "deliver [json string]", - Short: "deliver inbound messages", - Args: cobra.ExactArgs(1), + Use: "deliver { | @- | @}", + Short: "send mailbox messages", + Long: `send mailbox messages. +Input must represent an array in which the first element is an array of +[messageNum: integer, messageBody: string] pairs and the second element is +an "Ack" integer.`, + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { cctx, err := client.GetClientTxContext(cmd) @@ -91,7 +96,11 @@ func GetCmdDeliver() *cobra.Command { // InstallBundle message in a transaction. func GetCmdInstallBundle() *cobra.Command { cmd := &cobra.Command{ - Use: "install-bundle /@/-", + Use: "install-bundle { | @- | @}", + Short: "install a bundle", + Long: `install a bundle. +Input should be endoZipBase64 JSON, but this is not verified. +https://github.com/endojs/endo/tree/master/packages/bundle-source`, Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { @@ -147,7 +156,7 @@ func GetCmdInstallBundle() *cobra.Command { // GetCmdProvision is the CLI command for sending a Provision transaction func GetCmdProvisionOne() *cobra.Command { cmd := &cobra.Command{ - Use: "provision-one [nickname] [address] [power-flags]", + Use: "provision-one
[[,...]]", Short: "provision a single address", Args: cobra.RangeArgs(2, 3), @@ -185,7 +194,7 @@ func GetCmdProvisionOne() *cobra.Command { // GetCmdWalletAction is the CLI command for sending a WalletAction or WalletSpendAction transaction func GetCmdWalletAction() *cobra.Command { cmd := &cobra.Command{ - Use: "wallet-action [json string]", + Use: "wallet-action ", Short: "perform a wallet action", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { @@ -220,9 +229,11 @@ func GetCmdWalletAction() *cobra.Command { return cmd } +// NewCmdSubmitCoreEvalProposal is the CLI command for submitting a "CoreEval" +// governance proposal via `agd tx gov submit-proposal swingset-core-eval ...`. func NewCmdSubmitCoreEvalProposal() *cobra.Command { cmd := &cobra.Command{ - Use: "swingset-core-eval [[permit.json] [code.js]]...", + Use: "swingset-core-eval ...", Args: cobra.MinimumNArgs(2), Short: "Submit a proposal to evaluate code in the SwingSet core", Long: `Submit a SwingSet evaluate core Compartment code proposal along with an initial deposit. diff --git a/golang/cosmos/x/vstorage/client/cli/query.go b/golang/cosmos/x/vstorage/client/cli/query.go index 92ab345a522..b4f008160d6 100644 --- a/golang/cosmos/x/vstorage/client/cli/query.go +++ b/golang/cosmos/x/vstorage/client/cli/query.go @@ -28,8 +28,8 @@ func GetQueryCmd(storeKey string) *cobra.Command { // GetCmdGetData queries information about storage func GetCmdGetData(queryRoute string) *cobra.Command { cmd := &cobra.Command{ - Use: "data [path]", - Short: "get vstorage data for path", + Use: "data ", + Short: "get data for vstorage path", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientQueryContext(cmd) @@ -60,8 +60,12 @@ func GetCmdGetChildren(queryRoute string) *cobra.Command { cmd := &cobra.Command{ Use: "children [path]", Aliases: []string{"keys"}, - Short: "get vstorage subkey names for path", - Args: cobra.MaximumNArgs(1), + Short: "get child path segments under vstorage path", + Long: `get child path segments under vstorage path. +When absent, path defaults to the empty root path. +Path segments are dot-separated, so a child "baz" under path "foo.bar" has path +"foo.bar.baz".`, + Args: cobra.MaximumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { @@ -92,7 +96,7 @@ func GetCmdGetChildren(queryRoute string) *cobra.Command { // GetCmdGetPath queries vstorage data or children, depending on the path func GetCmdGetPath(queryRoute string) *cobra.Command { cmd := &cobra.Command{ - Use: "path [path]", + Use: "path ", Short: "get vstorage data, or children if path ends with '.'", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { From 2463df59769f94b2b3e45e33ee752845b43700b1 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Tue, 19 Dec 2023 19:18:04 -0500 Subject: [PATCH 2/3] chore(agd testnet): Deprecate --v in favor of --validator-count, -n --- golang/cosmos/daemon/cmd/testnet.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/golang/cosmos/daemon/cmd/testnet.go b/golang/cosmos/daemon/cmd/testnet.go index 96aec369160..8a90d1eefef 100644 --- a/golang/cosmos/daemon/cmd/testnet.go +++ b/golang/cosmos/daemon/cmd/testnet.go @@ -37,7 +37,7 @@ import ( var ( flagNodeDirPrefix = "node-dir-prefix" - flagNumValidators = "v" + flagNumValidators = "validator-count" flagOutputDir = "output-dir" flagNodeDaemonHome = "node-daemon-home" flagStartingIPAddress = "starting-ip-address" @@ -54,7 +54,7 @@ necessary files (private validator, genesis, config, etc.). Note, strict routability for addresses is turned off in the config file. Example: - agd testnet --v 4 --output-dir ./output --starting-ip-address 192.168.10.2 + agd testnet -n 4 --output-dir ./output --starting-ip-address 192.168.10.2 `, RunE: func(cmd *cobra.Command, _ []string) error { clientCtx, err := client.GetClientQueryContext(cmd) @@ -74,6 +74,13 @@ Example: numValidators, _ := cmd.Flags().GetInt(flagNumValidators) algo, _ := cmd.Flags().GetString(flags.FlagKeyAlgorithm) + if cmd.Flags().Changed("v") { + if cmd.Flags().Changed(flagNumValidators) { + return fmt.Errorf("--%s and --v are mutually exclusive", flagNumValidators) + } + numValidators, _ = cmd.Flags().GetInt("v") + } + return InitTestnet( clientCtx, cmd, config, mbm, genBalIterator, outputDir, chainID, minGasPrices, nodeDirPrefix, nodeDaemonHome, startingIPAddress, keyringBackend, algo, numValidators, @@ -81,7 +88,11 @@ Example: }, } - cmd.Flags().Int(flagNumValidators, 4, "Number of validators to initialize the testnet with") + cmd.Flags().IntP(flagNumValidators, "n", 4, "Number of validators to initialize the testnet with") + cmd.Flags().Int("v", 4, fmt.Sprintf("Alias for --%s", flagNumValidators)) + if vFlag := cmd.Flags().Lookup("v"); vFlag != nil { + vFlag.Deprecated = fmt.Sprintf("use --%s", flagNumValidators) + } cmd.Flags().StringP(flagOutputDir, "o", "./mytestnet", "Directory to store initialization data for the testnet") cmd.Flags().String(flagNodeDirPrefix, "node", "Prefix for the name of per-validator subdirectories (to be number-suffixed like node0, node1, ...)") cmd.Flags().String(flagNodeDaemonHome, AppName, "Home directory of the node's daemon configuration") From 1279bec3688189dd61a070c032d5ab36c6a02da5 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Fri, 19 Jan 2024 10:27:30 -0500 Subject: [PATCH 3/3] chore(x/swingset): Adopt and explain conventions for file/inline CLI arguments --- golang/cosmos/x/swingset/client/cli/tx.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/golang/cosmos/x/swingset/client/cli/tx.go b/golang/cosmos/x/swingset/client/cli/tx.go index b6d2f7ee34b..4604fba4437 100644 --- a/golang/cosmos/x/swingset/client/cli/tx.go +++ b/golang/cosmos/x/swingset/client/cli/tx.go @@ -47,12 +47,14 @@ func GetTxCmd(storeKey string) *cobra.Command { // containing mailbox messages. func GetCmdDeliver() *cobra.Command { cmd := &cobra.Command{ - Use: "deliver { | @- | @}", + Use: "deliver { | @- | @}", Short: "send mailbox messages", Long: `send mailbox messages. +The argument indicates how to read input JSON ("@-" for standard input, +"@..." for a file path, and otherwise directly as in "deliver '[...]'"). Input must represent an array in which the first element is an array of -[messageNum: integer, messageBody: string] pairs and the second element is -an "Ack" integer.`, +[messageNum: integer, messageBody: string] pairs and the second element +is an "Ack" integer.`, Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { @@ -96,9 +98,12 @@ an "Ack" integer.`, // InstallBundle message in a transaction. func GetCmdInstallBundle() *cobra.Command { cmd := &cobra.Command{ - Use: "install-bundle { | @- | @}", + Use: "install-bundle { | @- | @}", Short: "install a bundle", Long: `install a bundle. +The argument indicates how to read input JSON ("@-" for standard input, +"@..." for a file path, and otherwise directly as in +"install-bundle '{...}'"). Input should be endoZipBase64 JSON, but this is not verified. https://github.com/endojs/endo/tree/master/packages/bundle-source`, Args: cobra.ExactArgs(1),