2016-06-03 01:09:14 +00:00
|
|
|
package command
|
2012-08-06 23:54:53 +00:00
|
|
|
|
|
|
|
import (
|
2013-01-17 08:56:56 +00:00
|
|
|
"fmt"
|
2021-02-20 08:52:57 +00:00
|
|
|
flag "github.com/chrislusf/seaweedfs/weed/util/fla9"
|
2013-01-17 08:56:56 +00:00
|
|
|
"os"
|
|
|
|
"strings"
|
2012-08-06 23:54:53 +00:00
|
|
|
)
|
|
|
|
|
2016-06-03 01:09:14 +00:00
|
|
|
var Commands = []*Command{
|
2021-08-02 18:49:40 +00:00
|
|
|
cmdAutocomplete,
|
|
|
|
cmdUnautocomplete,
|
2016-06-03 01:09:14 +00:00
|
|
|
cmdBackup,
|
2021-07-24 01:44:53 +00:00
|
|
|
cmdBenchmark,
|
2016-06-03 01:09:14 +00:00
|
|
|
cmdCompact,
|
2020-04-05 07:51:16 +00:00
|
|
|
cmdDownload,
|
|
|
|
cmdExport,
|
|
|
|
cmdFiler,
|
2021-03-01 00:22:27 +00:00
|
|
|
cmdFilerBackup,
|
2021-01-06 12:21:34 +00:00
|
|
|
cmdFilerCat,
|
2021-07-24 01:44:53 +00:00
|
|
|
cmdFilerCopy,
|
2021-03-03 10:02:29 +00:00
|
|
|
cmdFilerMetaBackup,
|
2021-01-13 02:48:01 +00:00
|
|
|
cmdFilerMetaTail,
|
2021-09-16 05:48:04 +00:00
|
|
|
cmdFilerRemoteGateway,
|
2021-08-08 08:21:42 +00:00
|
|
|
cmdFilerRemoteSynchronize,
|
2018-09-17 07:27:56 +00:00
|
|
|
cmdFilerReplicate,
|
2020-09-09 18:21:23 +00:00
|
|
|
cmdFilerSynchronize,
|
2020-04-05 07:51:16 +00:00
|
|
|
cmdFix,
|
2021-05-26 02:32:35 +00:00
|
|
|
cmdFuse,
|
2016-06-03 01:09:14 +00:00
|
|
|
cmdMaster,
|
2021-08-13 01:10:59 +00:00
|
|
|
cmdMasterFollower,
|
2020-04-05 07:51:16 +00:00
|
|
|
cmdMount,
|
2018-07-18 09:37:09 +00:00
|
|
|
cmdS3,
|
2020-12-09 12:11:49 +00:00
|
|
|
cmdIam,
|
2020-03-04 08:39:47 +00:00
|
|
|
cmdMsgBroker,
|
2018-08-19 22:36:30 +00:00
|
|
|
cmdScaffold,
|
2020-04-05 07:51:16 +00:00
|
|
|
cmdServer,
|
2016-06-03 01:09:14 +00:00
|
|
|
cmdShell,
|
2020-04-05 07:51:16 +00:00
|
|
|
cmdUpload,
|
2016-06-03 01:09:14 +00:00
|
|
|
cmdVersion,
|
|
|
|
cmdVolume,
|
2019-05-02 21:22:10 +00:00
|
|
|
cmdWebDav,
|
2016-06-03 01:09:14 +00:00
|
|
|
}
|
|
|
|
|
2012-08-06 23:54:53 +00:00
|
|
|
type Command struct {
|
2013-01-17 08:56:56 +00:00
|
|
|
// Run runs the command.
|
|
|
|
// The args are the arguments after the command name.
|
|
|
|
Run func(cmd *Command, args []string) bool
|
2012-08-06 23:54:53 +00:00
|
|
|
|
2013-01-17 08:56:56 +00:00
|
|
|
// UsageLine is the one-line usage message.
|
|
|
|
// The first word in the line is taken to be the command name.
|
|
|
|
UsageLine string
|
2012-08-06 23:54:53 +00:00
|
|
|
|
2013-01-17 08:56:56 +00:00
|
|
|
// Short is the short description shown in the 'go help' output.
|
|
|
|
Short string
|
2012-08-06 23:54:53 +00:00
|
|
|
|
2013-01-17 08:56:56 +00:00
|
|
|
// Long is the long message shown in the 'go help <this-command>' output.
|
|
|
|
Long string
|
2012-08-06 23:54:53 +00:00
|
|
|
|
2013-01-17 08:56:56 +00:00
|
|
|
// Flag is a set of flags specific to this command.
|
|
|
|
Flag flag.FlagSet
|
2013-01-20 03:49:57 +00:00
|
|
|
|
|
|
|
IsDebug *bool
|
2012-08-06 23:54:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Name returns the command's name: the first word in the usage line.
|
|
|
|
func (c *Command) Name() string {
|
2013-01-17 08:56:56 +00:00
|
|
|
name := c.UsageLine
|
|
|
|
i := strings.Index(name, " ")
|
|
|
|
if i >= 0 {
|
|
|
|
name = name[:i]
|
|
|
|
}
|
|
|
|
return name
|
2012-08-06 23:54:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Command) Usage() {
|
2013-01-17 08:56:56 +00: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)
|
2012-08-06 23:54:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 08:56:56 +00:00
|
|
|
return c.Run != nil
|
2012-08-06 23:54:53 +00:00
|
|
|
}
|