command.go 1.8 KB

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