8 "github.com/spf13/cobra"
10 "github.com/bytom/util"
13 // commandError is an error used to signal different error situations in command handling.
14 type commandError struct {
19 func (c commandError) Error() string {
23 func (c commandError) isUserError() bool {
27 func newUserError(a ...interface{}) commandError {
28 return commandError{s: fmt.Sprintln(a...), userError: true}
31 func newSystemError(a ...interface{}) commandError {
32 return commandError{s: fmt.Sprintln(a...), userError: false}
35 func newSystemErrorF(format string, a ...interface{}) commandError {
36 return commandError{s: fmt.Sprintf(format, a...), userError: false}
39 // Catch some of the obvious user errors from Cobra.
40 // We don't want to show the usage message for every error.
41 // The below may be to generic. Time will show.
42 var userErrorRegexp = regexp.MustCompile("argument|flag|shorthand")
44 func isUserError(err error) bool {
45 if cErr, ok := err.(commandError); ok && cErr.isUserError() {
49 return userErrorRegexp.MatchString(err.Error())
52 // BytomcliCmd is Bytomcli's root command.
53 // Every other command attached to BytomcliCmd is a child command to it.
54 var BytomcliCmd = &cobra.Command{
56 Short: "Bytomcli is a commond line client for bytom core (a.k.a. bytomd)",
57 Run: func(cmd *cobra.Command, args []string) {
64 // Execute adds all child commands to the root command BytomcliCmd and sets flags appropriately.
69 if _, err := BytomcliCmd.ExecuteC(); err != nil {
70 os.Exit(util.ErrLocalExe)
74 // AddCommands adds child commands to the root command BytomcliCmd.
76 BytomcliCmd.AddCommand(createAccessTokenCmd)
77 BytomcliCmd.AddCommand(listAccessTokenCmd)
78 BytomcliCmd.AddCommand(deleteAccessTokenCmd)
79 BytomcliCmd.AddCommand(checkAccessTokenCmd)
81 BytomcliCmd.AddCommand(createAccountCmd)
82 BytomcliCmd.AddCommand(deleteAccountCmd)
83 BytomcliCmd.AddCommand(listAccountsCmd)
84 BytomcliCmd.AddCommand(createAccountReceiverCmd)
85 BytomcliCmd.AddCommand(listAddressesCmd)
86 BytomcliCmd.AddCommand(validateAddressCmd)
88 BytomcliCmd.AddCommand(createAssetCmd)
89 BytomcliCmd.AddCommand(listAssetsCmd)
90 BytomcliCmd.AddCommand(updateAssetAliasCmd)
92 BytomcliCmd.AddCommand(getTransactionCmd)
93 BytomcliCmd.AddCommand(listTransactionsCmd)
94 BytomcliCmd.AddCommand(listUnspentOutputsCmd)
95 BytomcliCmd.AddCommand(listBalancesCmd)
97 BytomcliCmd.AddCommand(buildTransactionCmd)
98 BytomcliCmd.AddCommand(signTransactionCmd)
99 BytomcliCmd.AddCommand(submitTransactionCmd)
100 BytomcliCmd.AddCommand(calculateTransactionGasCmd)
101 BytomcliCmd.AddCommand(signSubTransactionCmd)
103 BytomcliCmd.AddCommand(getBlockCountCmd)
104 BytomcliCmd.AddCommand(blockHashCmd)
105 BytomcliCmd.AddCommand(getBlockCmd)
106 BytomcliCmd.AddCommand(getBlockHeaderByHashCmd)
107 BytomcliCmd.AddCommand(getBlockTransactionsCountByHashCmd)
108 BytomcliCmd.AddCommand(getBlockTransactionsCountByHeightCmd)
110 BytomcliCmd.AddCommand(createKeyCmd)
111 BytomcliCmd.AddCommand(deleteKeyCmd)
112 BytomcliCmd.AddCommand(listKeysCmd)
113 BytomcliCmd.AddCommand(resetKeyPwdCmd)
114 BytomcliCmd.AddCommand(exportPrivateCmd)
115 BytomcliCmd.AddCommand(importPrivateCmd)
116 BytomcliCmd.AddCommand(importKeyProgressCmd)
118 BytomcliCmd.AddCommand(isMiningCmd)
120 BytomcliCmd.AddCommand(netInfoCmd)
121 BytomcliCmd.AddCommand(netListeningCmd)
122 BytomcliCmd.AddCommand(peerCountCmd)
123 BytomcliCmd.AddCommand(netSyncingCmd)
125 BytomcliCmd.AddCommand(gasRateCmd)
127 BytomcliCmd.AddCommand(createTransactionFeedCmd)
128 BytomcliCmd.AddCommand(listTransactionFeedsCmd)
129 BytomcliCmd.AddCommand(deleteTransactionFeedCmd)
130 BytomcliCmd.AddCommand(getTransactionFeedCmd)
131 BytomcliCmd.AddCommand(updateTransactionFeedCmd)
133 BytomcliCmd.AddCommand(versionCmd)