command.go 1.7 KB

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