This repository has been archived by the owner on May 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
import.go
61 lines (52 loc) · 1.61 KB
/
import.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package cmd
import (
"log"
"os"
"github.com/findy-network/findy-agent/cmds/tools"
"github.com/lainio/err2"
"github.com/lainio/err2/try"
"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, _ []string) (err error) {
return BindEnvs(importEnvs, cmd.Name())
},
RunE: func(_ *cobra.Command, _ []string) (err error) {
defer err2.Handle(&err)
try.To(impCmd.Validate())
if !rootFlags.dryRun {
try.To1(impCmd.Exec(os.Stdout))
}
return nil
},
}
var impCmd = tools.ImportCmd{}
func init() {
defer err2.Catch(err2.Err(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)
}