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(updateAccountTagsCmd)
85 BytomcliCmd.AddCommand(createAccountReceiverCmd)
86 BytomcliCmd.AddCommand(createAccountAddressCmd)
88 BytomcliCmd.AddCommand(createAssetCmd)
89 BytomcliCmd.AddCommand(listAssetsCmd)
90 BytomcliCmd.AddCommand(updateAssetTagsCmd)
92 BytomcliCmd.AddCommand(listTransactionsCmd)
93 BytomcliCmd.AddCommand(listUnspentOutputsCmd)
94 BytomcliCmd.AddCommand(listBalancesCmd)
96 BytomcliCmd.AddCommand(buildTransactionCmd)
97 BytomcliCmd.AddCommand(signTransactionCmd)
98 BytomcliCmd.AddCommand(submitTransactionCmd)
99 BytomcliCmd.AddCommand(signSubTransactionCmd)
101 BytomcliCmd.AddCommand(blockHeightCmd)
102 BytomcliCmd.AddCommand(blockHashCmd)
103 BytomcliCmd.AddCommand(getBlockByHashCmd)
104 BytomcliCmd.AddCommand(getBlockHeaderByHashCmd)
105 BytomcliCmd.AddCommand(getBlockTransactionsCountByHashCmd)
106 BytomcliCmd.AddCommand(getBlockByHeightCmd)
107 BytomcliCmd.AddCommand(getBlockTransactionsCountByHeightCmd)
109 BytomcliCmd.AddCommand(createKeyCmd)
110 BytomcliCmd.AddCommand(deleteKeyCmd)
111 BytomcliCmd.AddCommand(listKeysCmd)
112 BytomcliCmd.AddCommand(exportPrivateCmd)
113 BytomcliCmd.AddCommand(importPrivateCmd)
115 BytomcliCmd.AddCommand(isMiningCmd)
117 BytomcliCmd.AddCommand(netInfoCmd)
118 BytomcliCmd.AddCommand(netListeningCmd)
119 BytomcliCmd.AddCommand(peerCountCmd)
120 BytomcliCmd.AddCommand(netSyncingCmd)
122 BytomcliCmd.AddCommand(gasRateCmd)
124 BytomcliCmd.AddCommand(createTransactionFeedCmd)
125 BytomcliCmd.AddCommand(listTransactionFeedsCmd)
126 BytomcliCmd.AddCommand(deleteTransactionFeedCmd)
127 BytomcliCmd.AddCommand(getTransactionFeedCmd)
128 BytomcliCmd.AddCommand(updateTransactionFeedCmd)
130 BytomcliCmd.AddCommand(versionCmd)