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.

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