-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cmd): pactus-wallet add info commands
- Loading branch information
Showing
3 changed files
with
103 additions
and
0 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,90 @@ | ||
package main | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/pactus-project/pactus/cmd" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// buildAllInfoCmd builds all sub-commands related to the wallet information. | ||
func buildAllInfoCmd(parentCmd *cobra.Command) { | ||
infoCmd := &cobra.Command{ | ||
Use: "info", | ||
Short: "retrieving the wallet information.", | ||
} | ||
|
||
parentCmd.AddCommand(infoCmd) | ||
buildWalletVersionInfoCmd(infoCmd) | ||
buildCreationTimeInfoCmd(infoCmd) | ||
buildIsEncryptedInfoCmd(infoCmd) | ||
buildNetworkInfoCmd(infoCmd) | ||
} | ||
|
||
// buildWalletVersionInfoCmd builds a command for retrieving the current wallet's version. | ||
func buildWalletVersionInfoCmd(parentCmd *cobra.Command) { | ||
walletVersionInfoCmd := &cobra.Command{ | ||
Use: "version", | ||
Short: "display the current version of the wallet.", | ||
} | ||
|
||
parentCmd.AddCommand(walletVersionInfoCmd) | ||
|
||
walletVersionInfoCmd.Run = func(_ *cobra.Command, _ []string) { | ||
wlt, err := openWallet() | ||
cmd.FatalErrorCheck(err) | ||
|
||
cmd.PrintInfoMsgf("version: %d", wlt.GetVersion()) | ||
} | ||
} | ||
|
||
// buildCreationTimeInfoCmd builds a command for retrieving the wallet's creation time. | ||
func buildCreationTimeInfoCmd(parentCmd *cobra.Command) { | ||
walletCreationTimeInfoCmd := &cobra.Command{ | ||
Use: "created-at", | ||
Short: "display the creation time of the wallet.", | ||
} | ||
|
||
parentCmd.AddCommand(walletCreationTimeInfoCmd) | ||
|
||
walletCreationTimeInfoCmd.Run = func(_ *cobra.Command, _ []string) { | ||
wlt, err := openWallet() | ||
cmd.FatalErrorCheck(err) | ||
|
||
cmd.PrintInfoMsgf("created at: %s", wlt.GetCreationTime().Format(time.RFC3339)) | ||
} | ||
} | ||
|
||
// buildIsEncryptedInfoCmd builds a command for knowing if the wallet is encrypted or not. | ||
func buildIsEncryptedInfoCmd(parentCmd *cobra.Command) { | ||
walletIsEncryptedInfoCmd := &cobra.Command{ | ||
Use: "is-encrypted", | ||
Short: "display if the wallet is encrypted or not.", | ||
} | ||
|
||
parentCmd.AddCommand(walletIsEncryptedInfoCmd) | ||
|
||
walletIsEncryptedInfoCmd.Run = func(_ *cobra.Command, _ []string) { | ||
wlt, err := openWallet() | ||
cmd.FatalErrorCheck(err) | ||
|
||
cmd.PrintInfoMsgf("is encrtypted: %t", wlt.IsEncrypted()) | ||
} | ||
} | ||
|
||
// buildNetworkInfoCmd builds a command for retrieving the wallet's network. | ||
func buildNetworkInfoCmd(parentCmd *cobra.Command) { | ||
walletNetworkInfoCmd := &cobra.Command{ | ||
Use: "network", | ||
Short: "display the network of the wallet.", | ||
} | ||
|
||
parentCmd.AddCommand(walletNetworkInfoCmd) | ||
|
||
walletNetworkInfoCmd.Run = func(_ *cobra.Command, _ []string) { | ||
wlt, err := openWallet() | ||
cmd.FatalErrorCheck(err) | ||
|
||
cmd.PrintInfoMsgf("network: %s", wlt.GetNetwork().String()) | ||
} | ||
} |
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
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