Guest User

Untitled

a guest
Dec 17th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. Usage:
  2. MZR [command]
  3.  
  4. Available Commands:
  5. echo Echo anything to the screen
  6. help Help about any command
  7. print Print anything to the screen
  8.  
  9. Flags:
  10. -h, --help help for MZR
  11.  
  12. Use "MZR [command] --help" for more information about a command.
  13.  
  14.  
  15. [Process completed]
  16.  
  17. package main
  18.  
  19. import (
  20. "fmt"
  21. "strings"
  22.  
  23. "github.com/spf13/cobra"
  24. )
  25.  
  26. func main() {
  27. var echoTimes int
  28.  
  29. var cmdPrint = &cobra.Command{
  30. Use: "print [string to print]",
  31. Short: "Print anything to the screen",
  32. Long: `print is for printing anything back to the screen.
  33. For many years people have printed back to the screen.`,
  34. Args: cobra.MinimumNArgs(1),
  35. Run: func(cmd *cobra.Command, args []string) {
  36. fmt.Println("Print: " + strings.Join(args, " "))
  37. },
  38. }
  39.  
  40. var cmdEcho = &cobra.Command{
  41. Use: "echo [string to echo]",
  42. Short: "Echo anything to the screen",
  43. Long: `echo is for echoing anything back.
  44. Echo works a lot like print, except it has a child command.`,
  45. Args: cobra.MinimumNArgs(1),
  46. Run: func(cmd *cobra.Command, args []string) {
  47. fmt.Println("Print: " + strings.Join(args, " "))
  48. },
  49. }
  50.  
  51. var cmdTimes = &cobra.Command{
  52. Use: "times [# times] [string to echo]",
  53. Short: "Echo anything to the screen more times",
  54. Long: `echo things multiple times back to the user by providing
  55. a count and a string.`,
  56. Args: cobra.MinimumNArgs(1),
  57. Run: func(cmd *cobra.Command, args []string) {
  58. for i := 0; i < echoTimes; i++ {
  59. fmt.Println("Echo: " + strings.Join(args, " "))
  60. }
  61. },
  62. }
  63.  
  64. cmdTimes.Flags().IntVarP(&echoTimes, "times", "t", 1, "times to echo the input")
  65.  
  66. var rootCmd = &cobra.Command{Use: "MZR"}
  67. rootCmd.AddCommand(cmdPrint, cmdEcho)
  68. cmdEcho.AddCommand(cmdTimes)
  69. rootCmd.Execute()
  70. }
Add Comment
Please, Sign In to add comment