From 87abef1e0ea3dadda1b1b04f5ef30e5ff6adaced Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 18 Jan 2018 12:38:39 +0100 Subject: [PATCH] Mock out chub keys commands --- examples/chub/key.go | 76 +++++++++++++++++++++++++++++++++++++++++++ examples/chub/main.go | 3 +- examples/chub/node.go | 2 +- 3 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 examples/chub/key.go diff --git a/examples/chub/key.go b/examples/chub/key.go new file mode 100644 index 0000000000..29ff1ec2a3 --- /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 761fe26f3e..be08229f45 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 3befdc3c82..3e349738d8 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, }