command.go 1.8 KB

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