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.

89 lines
1.8 KiB

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