added cli cobra

rebaseFixes

int

removed ExitOnErr

int

int

int

int

int

added uint64 to RegisterFlags
This commit is contained in:
rigelrozanski
2017-04-21 12:34:11 -04:00
committed by Ethan Buchman
parent c6e348e01b
commit fb3fd1b425
20 changed files with 716 additions and 726 deletions
+20 -24
View File
@@ -1,16 +1,32 @@
package main
import (
"github.com/spf13/cobra"
wire "github.com/tendermint/go-wire"
"github.com/urfave/cli"
"github.com/tendermint/basecoin/cmd/commands"
"github.com/tendermint/basecoin/types"
)
var (
//CLI Flags
validFlag bool
//CLI Plugin Commands
ExamplePluginTxCmd = &cobra.Command{
Use: "example",
Short: "Create, sign, and broadcast a transaction to the example plugin",
Run: examplePluginTxCmd,
}
)
//Called during CLI initialization
func init() {
//Set the Plugin Flags
ExamplePluginTxCmd.Flags().BoolVar(&validFlag, "valid", false, "Set this to make transaction valid")
//Register a plugin specific CLI command as a subcommand of the tx command
commands.RegisterTxSubcommand(ExamplePluginTxCmd)
@@ -18,32 +34,12 @@ func init() {
commands.RegisterStartPlugin("example-plugin", func() types.Plugin { return NewExamplePlugin() })
}
var (
//CLI Flags
ExampleFlag = cli.BoolFlag{
Name: "valid",
Usage: "Set this to make the transaction valid",
}
//CLI Plugin Commands
ExamplePluginTxCmd = cli.Command{
Name: "example",
Usage: "Create, sign, and broadcast a transaction to the example plugin",
Action: func(c *cli.Context) error {
return cmdExamplePluginTx(c)
},
Flags: append(commands.TxFlags, ExampleFlag),
}
)
//Send a transaction
func cmdExamplePluginTx(c *cli.Context) error {
//Retrieve any flag results
exampleFlag := c.Bool("valid")
func examplePluginTxCmd(cmd *cobra.Command, args []string) {
// Create a transaction using the flag.
// The tx passes on custom information to the plugin
exampleTx := ExamplePluginTx{exampleFlag}
exampleTx := ExamplePluginTx{validFlag}
// The tx is passed to the plugin in the form of
// a byte array. This is achieved by serializing the object using go-wire.
@@ -62,5 +58,5 @@ func cmdExamplePluginTx(c *cli.Context) error {
// - Once deserialized, the tx is passed to `state.ExecTx` (state/execution.go)
// - If the tx passes various checks, the `tx.Data` is forwarded as `txBytes` to `plugin.RunTx` (docs/guide/src/example-plugin/plugin.go)
// - Finally, it deserialized back to the ExamplePluginTx
return commands.AppTx(c, "example-plugin", exampleTxBytes)
commands.AppTx("example-plugin", exampleTxBytes)
}
+23 -9
View File
@@ -1,24 +1,38 @@
package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/tendermint/basecoin/cmd/commands"
"github.com/urfave/cli"
)
func main() {
//Initialize an instance of basecoin with default basecoin commands
app := cli.NewApp()
app.Name = "example-plugin"
app.Usage = "example-plugin [command] [args...]"
app.Version = "0.1.0"
app.Commands = []cli.Command{
//Initialize example-plugin root command
var RootCmd = &cobra.Command{
Use: "example-plugin",
Short: "example-plugin usage description",
}
//Add the default basecoin commands to the root command
RootCmd.AddCommand(
commands.InitCmd,
commands.StartCmd,
commands.TxCmd,
commands.KeyCmd,
commands.QueryCmd,
commands.KeyCmd,
commands.VerifyCmd,
commands.BlockCmd,
commands.AccountCmd,
commands.UnsafeResetAllCmd,
)
//Run the root command
if err := RootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
app.Run(os.Args)
}