forked from findy-network/findy-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add import & export cmd back to tools.
- Loading branch information
1 parent
b564c67
commit d23f684
Showing
7 changed files
with
246 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.