seaweedfs/weed/command/command.go

92 lines
1.8 KiB
Go
Raw Normal View History

package command
import (
2013-01-17 16:56:56 +08:00
"fmt"
"os"
"strings"
2022-06-14 19:01:57 +08:00
flag "github.com/chrislusf/seaweedfs/weed/util/fla9"
)
var Commands = []*Command{
2021-08-03 02:49:40 +08:00
cmdAutocomplete,
cmdUnautocomplete,
cmdBackup,
cmdBenchmark,
cmdCompact,
2020-04-05 15:51:16 +08:00
cmdDownload,
cmdExport,
cmdFiler,
cmdFilerBackup,
cmdFilerCat,
cmdFilerCopy,
2021-03-03 18:02:29 +08:00
cmdFilerMetaBackup,
cmdFilerMetaTail,
2021-09-16 13:48:04 +08:00
cmdFilerRemoteGateway,
2021-08-08 16:21:42 +08:00
cmdFilerRemoteSynchronize,
2018-09-17 15:27:56 +08:00
cmdFilerReplicate,
2020-09-10 02:21:23 +08:00
cmdFilerSynchronize,
2020-04-05 15:51:16 +08:00
cmdFix,
cmdFuse,
cmdMaster,
cmdMasterFollower,
2020-04-05 15:51:16 +08:00
cmdMount,
2018-07-18 17:37:09 +08:00
cmdS3,
2020-12-09 20:11:49 +08:00
cmdIam,
2020-03-04 16:39:47 +08:00
cmdMsgBroker,
2018-08-20 06:36:30 +08:00
cmdScaffold,
2020-04-05 15:51:16 +08:00
cmdServer,
cmdShell,
2020-04-05 15:51:16 +08:00
cmdUpload,
2022-06-14 19:01:57 +08:00
cmdUpdate,
cmdVersion,
cmdVolume,
cmdWebDav,
}
type Command struct {
2013-01-17 16:56:56 +08:00
// Run runs the command.
// The args are the arguments after the command name.
Run func(cmd *Command, args []string) bool
2013-01-17 16:56:56 +08:00
// UsageLine is the one-line usage message.
// The first word in the line is taken to be the command name.
UsageLine string
2013-01-17 16:56:56 +08:00
// Short is the short description shown in the 'go help' output.
Short string
2013-01-17 16:56:56 +08:00
// Long is the long message shown in the 'go help <this-command>' output.
Long string
2013-01-17 16:56:56 +08:00
// Flag is a set of flags specific to this command.
Flag flag.FlagSet
2013-01-20 11:49:57 +08:00
IsDebug *bool
}
// Name returns the command's name: the first word in the usage line.
func (c *Command) Name() string {
2013-01-17 16:56:56 +08:00
name := c.UsageLine
i := strings.Index(name, " ")
if i >= 0 {
name = name[:i]
}
return name
}
func (c *Command) Usage() {
2013-01-17 16:56:56 +08:00
fmt.Fprintf(os.Stderr, "Example: weed %s\n", c.UsageLine)
fmt.Fprintf(os.Stderr, "Default Usage:\n")
c.Flag.PrintDefaults()
fmt.Fprintf(os.Stderr, "Description:\n")
fmt.Fprintf(os.Stderr, " %s\n", strings.TrimSpace(c.Long))
os.Exit(2)
}
// Runnable reports whether the command can be run; otherwise
// it is a documentation pseudo-command such as importpath.
func (c *Command) Runnable() bool {
2013-01-17 16:56:56 +08:00
return c.Run != nil
}