command.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. cmdFilerMetaBackup,
  19. cmdFilerMetaTail,
  20. cmdFilerReplicate,
  21. cmdFilerSynchronize,
  22. cmdFix,
  23. cmdMaster,
  24. cmdMount,
  25. cmdS3,
  26. cmdMsgBroker,
  27. cmdScaffold,
  28. cmdServer,
  29. cmdShell,
  30. cmdUpload,
  31. cmdVersion,
  32. cmdVolume,
  33. cmdWebDav,
  34. }
  35. type Command struct {
  36. // Run runs the command.
  37. // The args are the arguments after the command name.
  38. Run func(cmd *Command, args []string) bool
  39. // UsageLine is the one-line usage message.
  40. // The first word in the line is taken to be the command name.
  41. UsageLine string
  42. // Short is the short description shown in the 'go help' output.
  43. Short string
  44. // Long is the long message shown in the 'go help <this-command>' output.
  45. Long string
  46. // Flag is a set of flags specific to this command.
  47. Flag flag.FlagSet
  48. IsDebug *bool
  49. }
  50. // Name returns the command's name: the first word in the usage line.
  51. func (c *Command) Name() string {
  52. name := c.UsageLine
  53. i := strings.Index(name, " ")
  54. if i >= 0 {
  55. name = name[:i]
  56. }
  57. return name
  58. }
  59. func (c *Command) Usage() {
  60. fmt.Fprintf(os.Stderr, "Example: weed %s\n", c.UsageLine)
  61. fmt.Fprintf(os.Stderr, "Default Usage:\n")
  62. c.Flag.PrintDefaults()
  63. fmt.Fprintf(os.Stderr, "Description:\n")
  64. fmt.Fprintf(os.Stderr, " %s\n", strings.TrimSpace(c.Long))
  65. os.Exit(2)
  66. }
  67. // Runnable reports whether the command can be run; otherwise
  68. // it is a documentation pseudo-command such as importpath.
  69. func (c *Command) Runnable() bool {
  70. return c.Run != nil
  71. }