cosmos-sdk/docs/sdk/sdk-by-examples/simple-governance/module-cli.md
gamarin2 c5fcc9b65f Add SDK_By_Examples to doc (#1795)
* Add simple gov example and sdk-by-example folder

* Add simple gov example

* Add simple gov example and sdk-by-example folder

* Add simple gov example

* fix sectino title

* Jb feedback + Offload some of the content in other docs

* Add what is cosmos back

* platform to framewoork

* Reemove testnet
2018-08-12 03:37:26 -04:00

1.1 KiB

Command-Line Interface (CLI)

File: x/simple_governance/client/cli/simple_governance.go

Go in the cli folder and create a simple_governance.go file. This is where we will define the commands for our module.

The CLI builds on top of Cobra. Here is the schema to build a command on top of Cobra:

    // Declare flags
    const(
        Flag = "flag"
        ...
    )

    // Main command function. One function for each command.
    func Command(codec *wire.Codec) *cobra.Command {
        // Create the command to return
        command := &cobra.Command{
            Use: "actual command",
            Short: "Short description",
            Run: func(cmd *cobra.Command, args []string) error {
                // Actual function to run when command is used
            },
        }

        // Add flags to the command
        command.Flags().<Type>(FlagNameConstant, <example_value>, "<Description>")

        return command
    }