diff --git a/examples/chub/key.go b/examples/chub/key.go new file mode 100644 index 000000000..29ff1ec2a --- /dev/null +++ b/examples/chub/key.go @@ -0,0 +1,76 @@ +package main + +import "github.com/spf13/cobra" + +const ( + flagPassword = "password" + flagNewPassword = "new-password" + flagType = "type" + flagSeed = "seed" + flagDryRun = "dry-run" +) + +var ( + listKeysCmd = &cobra.Command{ + Use: "list", + Short: "List all locally availably keys", + RunE: todoNotImplemented, + } + + showKeysCmd = &cobra.Command{ + Use: "show ", + Short: "Show key info for the given name", + RunE: todoNotImplemented, + } +) + +func keyCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "keys", + Short: "Add or view local private keys", + Run: help, + } + cmd.AddCommand( + addKeyCommand(), + listKeysCmd, + showKeysCmd, + lineBreak, + deleteKeyCommand(), + updateKeyCommand(), + ) + return cmd +} + +func addKeyCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "add ", + Short: "Create a new key, or import from seed", + RunE: todoNotImplemented, + } + cmd.Flags().StringP(flagPassword, "p", "", "password to encrypt private key") + cmd.Flags().StringP(flagType, "t", "ed25519", "type of private key (ed25519|secp256k1|ledger)") + cmd.Flags().StringP(flagSeed, "s", "", "Provide seed phrase to recover existing key instead of creating") + cmd.Flags().Bool(flagDryRun, false, "Perform action, but don't add key to local keystore") + return cmd +} + +func updateKeyCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "update ", + Short: "Change the password used to protect private key", + RunE: todoNotImplemented, + } + cmd.Flags().StringP(flagPassword, "p", "", "current password to decrypt key") + cmd.Flags().String(flagNewPassword, "", "new password to use to protect key") + return cmd +} + +func deleteKeyCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "delete ", + Short: "Delete the given key", + RunE: todoNotImplemented, + } + cmd.Flags().StringP(flagPassword, "p", "", "password of existing key to delete") + return cmd +} diff --git a/examples/chub/main.go b/examples/chub/main.go index 761fe26f3..be08229f4 100644 --- a/examples/chub/main.go +++ b/examples/chub/main.go @@ -38,12 +38,11 @@ func main() { var node app.App // add commands - // prepareRestServerCommands() // prepareClientCommands() chubCmd.AddCommand( nodeCommand(node), - // restServerCmd, + keyCommand(), // clientCmd, lineBreak, diff --git a/examples/chub/node.go b/examples/chub/node.go index 3befdc3c8..3e349738d 100644 --- a/examples/chub/node.go +++ b/examples/chub/node.go @@ -8,7 +8,7 @@ import ( var ( initNodeCmd = &cobra.Command{ - Use: "init", + Use: "init ", Short: "Initialize full node", RunE: todoNotImplemented, }