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.

92 lines
1.8 KiB

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