cubefs/cli/cmd/root.go
leonrayang 9a30b9f884 update: update to CubeFS
Signed-off-by: leonrayang <chl696@sina.com>
2022-08-22 18:16:09 +08:00

82 lines
1.9 KiB
Go

// Copyright 2018 The CubeFS Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
package cmd
import (
"fmt"
"os"
"path"
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/sdk/master"
"github.com/cubefs/cubefs/util/log"
"github.com/spf13/cobra"
)
const (
cmdRootShort = "CubeFS Command Line Interface (CLI)"
)
type CubeFSCmd struct {
CFSCmd *cobra.Command
}
func NewRootCmd(client *master.MasterClient) *CubeFSCmd {
var optShowVersion bool
var cmd = &CubeFSCmd{
CFSCmd: &cobra.Command{
Use: path.Base(os.Args[0]),
Short: cmdRootShort,
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
if optShowVersion {
stdout(proto.DumpVersion("CLI"))
return
}
},
},
}
cmd.CFSCmd.Flags().BoolVarP(&optShowVersion, "version", "v", false, "Show version information")
cmd.CFSCmd.AddCommand(
cmd.newClusterCmd(client),
newVolCmd(client),
newUserCmd(client),
newMetaNodeCmd(client),
newDataNodeCmd(client),
newDataPartitionCmd(client),
newMetaPartitionCmd(client),
newConfigCmd(),
newZoneCmd(client),
)
return cmd
}
func stdout(format string, a ...interface{}) {
_, _ = fmt.Fprintf(os.Stdout, format, a...)
}
func errout(format string, a ...interface{}) {
log.LogErrorf(format+"\n", a...)
_, _ = fmt.Fprintf(os.Stderr, format, a...)
OsExitWithLogFlush()
}
func OsExitWithLogFlush() {
log.LogFlush()
os.Exit(1)
}