version.go 416 B

123456789101112131415161718192021222324252627
  1. package cmd
  2. import (
  3. "fmt"
  4. "os"
  5. "github.com/spf13/cobra"
  6. )
  7. var versionCmd = &cobra.Command{
  8. Use: "version",
  9. Short: "version 子命令.",
  10. Long: "这是一个version 子命令",
  11. Run: runVersion,
  12. }
  13. func init() {
  14. rootCmd.AddCommand(versionCmd)
  15. }
  16. func runVersion(cmd *cobra.Command, args []string) {
  17. // TODO 这里处理version子命令
  18. fmt.Println("version is 1.0.0")
  19. // 终止程序
  20. os.Exit(0)
  21. }