diff --git a/cmd/celestia/admin.go b/cmd/celestia/admin.go index 89f30f508e..6c6ca1cf4f 100644 --- a/cmd/celestia/admin.go +++ b/cmd/celestia/admin.go @@ -1,17 +1,37 @@ package main import ( - "fmt" + "context" + "errors" "strings" "github.com/filecoin-project/go-jsonrpc/auth" "github.com/spf13/cobra" - - "github.com/celestiaorg/celestia-node/cmd" ) +func init() { + adminCmd.AddCommand(nodeInfoCmd, logCmd, verifyCmd, authCmd) + rootCmd.AddCommand(adminCmd) +} + +var adminCmd = &cobra.Command{ + Use: "admin [command]", + Short: "Allows to interact with the \"administrative\" node.", + Args: cobra.NoArgs, + PersistentPreRunE: func(cmd *cobra.Command, args []string) error { + rpcClient, err := newRPCClient(cmd.Context()) + if err != nil { + return err + } + + ctx := context.WithValue(cmd.Context(), rpcClientKey{}, rpcClient) + cmd.SetContext(ctx) + return nil + }, +} + var nodeInfoCmd = &cobra.Command{ - Use: "node.info", + Use: "node-info", Args: cobra.NoArgs, Short: "Returns administrative information about the node.", RunE: func(c *cobra.Command, args []string) error { @@ -25,7 +45,7 @@ var nodeInfoCmd = &cobra.Command{ } var logCmd = &cobra.Command{ - Use: cmd.LogLevelFlag, + Use: "log-level", Args: cobra.MinimumNArgs(1), Short: "Allows to set log level for module to in format :" + "`DEBUG, INFO, WARN, ERROR, DPANIC, PANIC, FATAL and their lower-case forms`.\n" + @@ -39,8 +59,8 @@ var logCmd = &cobra.Command{ for _, ll := range args { params := strings.Split(ll, ":") if len(params) != 2 { - return fmt.Errorf("cmd: %s arg must be in form :,"+ - "e.g. pubsub:debug", cmd.LogLevelFlag) + return errors.New("cmd: log-level arg must be in form :," + + "e.g. pubsub:debug") } if err = client.Node.LogLevelSet(c.Context(), params[0], params[1]); err != nil { @@ -68,7 +88,7 @@ var verifyCmd = &cobra.Command{ } var authCmd = &cobra.Command{ - Use: "set.permissions", + Use: "set-permissions", Args: cobra.MinimumNArgs(1), Short: "Signs and returns a new token with the given permissions.", RunE: func(c *cobra.Command, args []string) error { diff --git a/cmd/celestia/rpc.go b/cmd/celestia/rpc.go index bce7b2b736..a0dea6e0dd 100644 --- a/cmd/celestia/rpc.go +++ b/cmd/celestia/rpc.go @@ -60,7 +60,6 @@ func init() { false, "Print JSON-RPC request along with the response", ) - rpcCmd.AddCommand(nodeInfoCmd, logCmd, verifyCmd, authCmd) rpcCmd.AddCommand(blobCmd) rpcCmd.AddCommand(p2pCmd) rpcCmd.AddCommand(dasCmd)