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.

85 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. }
  38. type Command struct {
  39. // Run runs the command.
  40. // The args are the arguments after the command name.
  41. Run func(cmd *Command, args []string) bool
  42. // UsageLine is the one-line usage message.
  43. // The first word in the line is taken to be the command name.
  44. UsageLine string
  45. // Short is the short description shown in the 'go help' output.
  46. Short string
  47. // Long is the long message shown in the 'go help <this-command>' output.
  48. Long string
  49. // Flag is a set of flags specific to this command.
  50. Flag flag.FlagSet
  51. IsDebug *bool
  52. }
  53. // Name returns the command's name: the first word in the usage line.
  54. func (c *Command) Name() string {
  55. name := c.UsageLine
  56. i := strings.Index(name, " ")
  57. if i >= 0 {
  58. name = name[:i]
  59. }
  60. return name
  61. }
  62. func (c *Command) Usage() {
  63. fmt.Fprintf(os.Stderr, "Example: weed %s\n", c.UsageLine)
  64. fmt.Fprintf(os.Stderr, "Default Usage:\n")
  65. c.Flag.PrintDefaults()
  66. fmt.Fprintf(os.Stderr, "Description:\n")
  67. fmt.Fprintf(os.Stderr, " %s\n", strings.TrimSpace(c.Long))
  68. os.Exit(2)
  69. }
  70. // Runnable reports whether the command can be run; otherwise
  71. // it is a documentation pseudo-command such as importpath.
  72. func (c *Command) Runnable() bool {
  73. return c.Run != nil
  74. }