You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.6 KiB

5 years ago
  1. package command
  2. import (
  3. "fmt"
  4. flag "github.com/chrislusf/seaweedfs/weed/util/fla9"
  5. "os"
  6. "strings"
  7. )
  8. var Commands = []*Command{
  9. cmdBenchmark,
  10. cmdBackup,
  11. cmdCompact,
  12. cmdCopy,
  13. cmdDownload,
  14. cmdExport,
  15. cmdFiler,
  16. cmdFilerBackup,
  17. cmdFilerCat,
  18. cmdFilerMetaTail,
  19. cmdFilerReplicate,
  20. cmdFilerSynchronize,
  21. cmdFix,
  22. cmdMaster,
  23. cmdMount,
  24. cmdS3,
  25. cmdMsgBroker,
  26. cmdScaffold,
  27. cmdServer,
  28. cmdShell,
  29. cmdUpload,
  30. cmdVersion,
  31. cmdVolume,
  32. cmdWebDav,
  33. }
  34. type Command struct {
  35. // Run runs the command.
  36. // The args are the arguments after the command name.
  37. Run func(cmd *Command, args []string) bool
  38. // UsageLine is the one-line usage message.
  39. // The first word in the line is taken to be the command name.
  40. UsageLine string
  41. // Short is the short description shown in the 'go help' output.
  42. Short string
  43. // Long is the long message shown in the 'go help <this-command>' output.
  44. Long string
  45. // Flag is a set of flags specific to this command.
  46. Flag flag.FlagSet
  47. IsDebug *bool
  48. }
  49. // Name returns the command's name: the first word in the usage line.
  50. func (c *Command) Name() string {
  51. name := c.UsageLine
  52. i := strings.Index(name, " ")
  53. if i >= 0 {
  54. name = name[:i]
  55. }
  56. return name
  57. }
  58. func (c *Command) Usage() {
  59. fmt.Fprintf(os.Stderr, "Example: weed %s\n", c.UsageLine)
  60. fmt.Fprintf(os.Stderr, "Default Usage:\n")
  61. c.Flag.PrintDefaults()
  62. fmt.Fprintf(os.Stderr, "Description:\n")
  63. fmt.Fprintf(os.Stderr, " %s\n", strings.TrimSpace(c.Long))
  64. os.Exit(2)
  65. }
  66. // Runnable reports whether the command can be run; otherwise
  67. // it is a documentation pseudo-command such as importpath.
  68. func (c *Command) Runnable() bool {
  69. return c.Run != nil
  70. }