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.

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