Skip to content

Commit

Permalink
Add import & export cmd back to tools.
Browse files Browse the repository at this point in the history
  • Loading branch information
lauravuo-techlab authored and techlab-lainio committed Sep 21, 2021
1 parent b564c67 commit d23f684
Show file tree
Hide file tree
Showing 7 changed files with 246 additions and 303 deletions.
62 changes: 62 additions & 0 deletions cmd/export.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package cmd

import (
"log"
"os"

"github.com/findy-network/findy-agent/cmds/tools"
"github.com/lainio/err2"
"github.com/spf13/cobra"
)

var exportEnvs = map[string]string{
"wallet-name": "WALLET_NAME",
"wallet-key": "WALLET_KEY",
"file": "WALLET_FILE",
"key": "WALLET_FILE_KEY",
"legacy-wallet-key": "WALLET_LEGACY_KEY",
}

// exportCmd represents the export subcommand
var exportCmd = &cobra.Command{
Use: "export",
Short: "Command for exporting wallet",
Long: `
Command for exporting wallet
Example
findy-agent tools export \
--wallet-name MyWallet \
--wallet-key 6cih1cVgRH8...dv67o8QbufxaTHot3Qxp \
--key walletExportKey \
--file path/to/my-export-wallet
`,
PreRunE: func(cmd *cobra.Command, args []string) (err error) {
return BindEnvs(exportEnvs, cmd.Name())
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
defer err2.Return(&err)
err2.Check(expCmd.Validate())
if !rootFlags.dryRun {
err2.Try(expCmd.Exec(os.Stdout))
}
return nil
},
}

var expCmd = tools.ExportCmd{}

func init() {
defer err2.Catch(func(err error) {
log.Println(err)
})

flags := exportCmd.Flags()
flags.StringVar(&expCmd.WalletName, "wallet-name", "", flagInfo("wallet name", exportCmd.Name(), exportEnvs["wallet-name"]))
flags.StringVar(&expCmd.WalletKey, "wallet-key", "", flagInfo("wallet key", exportCmd.Name(), exportEnvs["wallet-key"]))
flags.StringVar(&expCmd.Filename, "file", "", flagInfo("full export file path", exportCmd.Name(), exportEnvs["file"]))
flags.StringVar(&expCmd.ExportKey, "key", "", flagInfo("wallet export key", exportCmd.Name(), exportEnvs["key"]))
flags.BoolVar(&expCmd.WalletKeyLegacy, "legacy-wallet-key", false, flagInfo("use old wallet key", exportCmd.Name(), exportEnvs["legacy-wallet-key"]))

toolsCmd.AddCommand(exportCmd)
}
60 changes: 60 additions & 0 deletions cmd/import.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package cmd

import (
"log"
"os"

"github.com/findy-network/findy-agent/cmds/tools"
"github.com/lainio/err2"
"github.com/spf13/cobra"
)

var importEnvs = map[string]string{
"wallet-name": "WALLET_NAME",
"wallet-key": "WALLET_KEY",
"file": "WALLET_FILE",
"key": "WALLET_FILE_KEY",
}

// importCmd represents the import command
var importCmd = &cobra.Command{
Use: "import",
Short: "Command for importing wallet",
Long: `
Command for importing wallet
Example
findy-agent tools import \
--wallet-name MyWallet \
--wallet-key 6cih1cVgRH8...dv67o8QbufxaTHot3Qxp \
--key walletImportKey \
--file /path/to/my-import-wallet
`,
PreRunE: func(cmd *cobra.Command, args []string) (err error) {
return BindEnvs(importEnvs, cmd.Name())
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
defer err2.Return(&err)
err2.Check(impCmd.Validate())
if !rootFlags.dryRun {
err2.Try(impCmd.Exec(os.Stdout))
}
return nil
},
}

var impCmd = tools.ImportCmd{}

func init() {
defer err2.Catch(func(err error) {
log.Println(err)
})

flags := importCmd.Flags()
flags.StringVar(&impCmd.WalletName, "wallet-name", "", flagInfo("wallet name", importCmd.Name(), importEnvs["wallet-name"]))
flags.StringVar(&impCmd.WalletKey, "wallet-key", "", flagInfo("wallet key", importCmd.Name(), importEnvs["wallet-key"]))
flags.StringVar(&impCmd.Filename, "file", "", flagInfo("full import file path", importCmd.Name(), importEnvs["file"]))
flags.StringVar(&impCmd.Key, "key", "", flagInfo("wallet import key", importCmd.Name(), importEnvs["key"]))

toolsCmd.AddCommand(importCmd)
}
51 changes: 0 additions & 51 deletions cmd/user.go

This file was deleted.

Loading

0 comments on commit d23f684

Please sign in to comment.