Skip to content
Myr

cmd_test.go

This file

Path

doc/cmd_test.go

91 lines · 2.9 KiB · Go

Last changed by

doc: GenMarkdown skip Synopsis on empty long cmd (#1207)Marc Lopez Rubiobefore adoption02a0d2f

History of this file

Take it

The walk stopped after 200 commits: lines older than 0ea93dd point at it.

Fixed linter issuesJuan Lenibefore adoption0ea93dd

lines 1–29why, one step back
1package doc
23import (4 "strings"5 "testing"67 "github.com/spf13/cobra"8)910func emptyRun(*cobra.Command, []string) {}1112func init() {13 rootCmd.PersistentFlags().StringP("rootflag", "r", "two", "")14 rootCmd.PersistentFlags().StringP("strtwo", "t", "two", "help message for parent flag strtwo")1516 echoCmd.PersistentFlags().StringP("strone", "s", "one", "help message for flag strone")17 echoCmd.PersistentFlags().BoolP("persistentbool", "p", false, "help message for flag persistentbool")18 echoCmd.Flags().IntP("intone", "i", 123, "help message for flag intone")19 echoCmd.Flags().BoolP("boolone", "b", true, "help message for flag boolone")2021 timesCmd.PersistentFlags().StringP("strtwo", "t", "2", "help message for child flag strtwo")22 timesCmd.Flags().IntP("inttwo", "j", 234, "help message for flag inttwo")23 timesCmd.Flags().BoolP("booltwo", "c", false, "help message for flag booltwo")2425 printCmd.PersistentFlags().StringP("strthree", "s", "three", "help message for flag strthree")26 printCmd.Flags().IntP("intthree", "i", 345, "help message for flag intthree")27 printCmd.Flags().BoolP("boolthree", "b", true, "help message for flag boolthree")2829 echoCmd.AddCommand(timesCmd, echoSubCmd, deprecatedCmd)

doc: GenMarkdown skip Synopsis on empty long cmd (#1207)Marc Lopez Rubiobefore adoption02a0d2f

line 30why, one step back
30 rootCmd.AddCommand(printCmd, echoCmd, dummyCmd)

Fixed linter issuesJuan Lenibefore adoption0ea93dd

lines 31–73why, one step back
31}
3233var rootCmd = &cobra.Command{34 Use: "root",35 Short: "Root short description",36 Long: "Root long description",37 Run: emptyRun,38}3940var echoCmd = &cobra.Command{41 Use: "echo [string to echo]",42 Aliases: []string{"say"},43 Short: "Echo anything to the screen",44 Long: "an utterly useless command for testing",45 Example: "Just run cobra-test echo",46}4748var echoSubCmd = &cobra.Command{49 Use: "echosub [string to print]",50 Short: "second sub command for echo",51 Long: "an absolutely utterly useless command for testing gendocs!.",52 Run: emptyRun,53}5455var timesCmd = &cobra.Command{56 Use: "times [# times] [string to echo]",57 SuggestFor: []string{"counts"},58 Short: "Echo anything to the screen more times",59 Long: `a slightly useless command for testing.`,60 Run: emptyRun,61}6263var deprecatedCmd = &cobra.Command{64 Use: "deprecated [can't do anything here]",65 Short: "A command which is deprecated",66 Long: `an absolutely utterly useless command for testing deprecation!.`,67 Deprecated: "Please use echo instead",68}6970var printCmd = &cobra.Command{71 Use: "print [string to print]",72 Short: "Print anything to the screen",73 Long: `an absolutely utterly useless command for testing.`,

doc: GenMarkdown skip Synopsis on empty long cmd (#1207)Marc Lopez Rubiobefore adoption02a0d2f

lines 74–78why, one step back
74}
7576var dummyCmd = &cobra.Command{77 Use: "dummy [action]",78 Short: "Performs a dummy action",

Fixed linter issuesJuan Lenibefore adoption0ea93dd

lines 79–91why, one step back
79}
8081func checkStringContains(t *testing.T, got, expected string) {82 if !strings.Contains(got, expected) {83 t.Errorf("Expected to contain: \n %v\nGot:\n %v\n", expected, got)84 }85}8687func checkStringOmits(t *testing.T, got, expected string) {88 if strings.Contains(got, expected) {89 t.Errorf("Expected to not contain: \n %v\nGot: %v", expected, got)90 }91}