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.

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