| 1 | package cliscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/ |
| 2 | |
| 3 | import ( |
| 4 | "bytesscip-go gomod github.com/golang/go/src go1.22 bytes/" |
| 5 | "contextscip-go gomod github.com/golang/go/src go1.22 context/" |
| 6 | "errorsscip-go gomod github.com/golang/go/src go1.22 errors/" |
| 7 | "fmtscip-go gomod github.com/golang/go/src go1.22 fmt/" |
| 8 | "ioscip-go gomod github.com/golang/go/src go1.22 io/" |
| 9 | "stringsscip-go gomod github.com/golang/go/src go1.22 strings/" |
| 10 | "testingscip-go gomod github.com/golang/go/src go1.22 testing/" |
| 11 | |
| 12 | "github.com/stretchr/testify/assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/" |
| 13 | "github.com/stretchr/testify/requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/" |
| 14 | ) |
| 15 | |
| 16 | func TestCompletionHelpscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TestCompletionHelp().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 17 | tests := []struct { |
| 18 | name string |
| 19 | args []string |
| 20 | }{ |
| 21 | { |
| 22 | name: "short help flag", |
| 23 | args: []string{"foo", completionCommandNamescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionCommandName., "-h"}, |
| 24 | }, |
| 25 | { |
| 26 | name: "long help flag", |
| 27 | args: []string{"foo", completionCommandNamescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionCommandName., "--help"}, |
| 28 | }, |
| 29 | { |
| 30 | name: "completion bash short help flag", |
| 31 | args: []string{"foo", completionCommandNamescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionCommandName., "bash", "-h"}, |
| 32 | }, |
| 33 | { |
| 34 | name: "completion bash long help flag", |
| 35 | args: []string{"foo", completionCommandNamescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionCommandName., "bash", "--help"}, |
| 36 | }, |
| 37 | } |
| 38 | |
| 39 | for _, test := range tests { |
| 40 | t.Runscip-go gomod github.com/golang/go/src go1.22 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 41 | out := &bytesscip-go gomod github.com/golang/go/src go1.22 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.22 bytes/Buffer#{} |
| 42 | |
| 43 | cmd := &Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 44 | EnableShellCompletionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#EnableShellCompletion.: true, |
| 45 | Writerscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Writer.: out, |
| 46 | Flagsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Flags.: []Flagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Flag#{ |
| 47 | &StringFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/StringFlag#{ |
| 48 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/FlagBase#Name.: "required-flag", |
| 49 | Requiredscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/FlagBase#Required.: true, |
| 50 | }, |
| 51 | }, |
| 52 | } |
| 53 | |
| 54 | r := requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Newscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/New().(t) |
| 55 | |
| 56 | r.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NoError().(cmd.Runscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Run().(buildTestContextscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/buildTestContext().(t), test.args)) |
| 57 | r.Containsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#Contains().(out.Stringscip-go gomod github.com/golang/go/src go1.22 bytes/Buffer#String().(), "USAGE") |
| 58 | r.NotContainsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NotContains().(out.Stringscip-go gomod github.com/golang/go/src go1.22 bytes/Buffer#String().(), "GLOBAL OPTIONS") |
| 59 | }) |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | func TestCompletionDisablescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TestCompletionDisable().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 64 | cmd := &Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{} |
| 65 | |
| 66 | err := cmd.Runscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Run().(buildTestContextscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/buildTestContext().(t), []string{"foo", completionCommandNamescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionCommandName.}) |
| 67 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Errorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Error().(t, err, "Expected error for no help topic for completion") |
| 68 | } |
| 69 | |
| 70 | func TestCompletionEnablescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TestCompletionEnable().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 71 | out := &bytesscip-go gomod github.com/golang/go/src go1.22 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.22 bytes/Buffer#{} |
| 72 | |
| 73 | cmd := &Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 74 | EnableShellCompletionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#EnableShellCompletion.: true, |
| 75 | Writerscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Writer.: out, |
| 76 | Flagsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Flags.: []Flagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Flag#{ |
| 77 | &StringFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/StringFlag#{ |
| 78 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/FlagBase#Name.: "goo", |
| 79 | Requiredscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/FlagBase#Required.: true, |
| 80 | }, |
| 81 | }, |
| 82 | } |
| 83 | |
| 84 | r := requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Newscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/New().(t) |
| 85 | r.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NoError().(cmd.Runscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Run().(buildTestContextscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/buildTestContext().(t), []string{"foo", completionCommandNamescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionCommandName.})) |
| 86 | r.Containsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#Contains().(out.Stringscip-go gomod github.com/golang/go/src go1.22 bytes/Buffer#String().(), "USAGE") |
| 87 | } |
| 88 | |
| 89 | func TestCompletionEnableDiffCommandNamescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TestCompletionEnableDiffCommandName().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 90 | out := &bytesscip-go gomod github.com/golang/go/src go1.22 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.22 bytes/Buffer#{} |
| 91 | |
| 92 | cmd := &Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 93 | EnableShellCompletionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#EnableShellCompletion.: true, |
| 94 | ShellCompletionCommandNamescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#ShellCompletionCommandName.: "junky", |
| 95 | Writerscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Writer.: out, |
| 96 | } |
| 97 | |
| 98 | r := requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Newscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/New().(t) |
| 99 | r.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NoError().(cmd.Runscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Run().(buildTestContextscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/buildTestContext().(t), []string{"foo", "junky"})) |
| 100 | r.Containsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#Contains().(out.Stringscip-go gomod github.com/golang/go/src go1.22 bytes/Buffer#String().(), "USAGE") |
| 101 | } |
| 102 | |
| 103 | func TestCompletionShellscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TestCompletionShell().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 104 | for k := range shellCompletionsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/shellCompletions. { |
| 105 | out := &bytesscip-go gomod github.com/golang/go/src go1.22 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.22 bytes/Buffer#{} |
| 106 | |
| 107 | t.Runscip-go gomod github.com/golang/go/src go1.22 testing/T#Run().(k, func(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 108 | cmd := &Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 109 | EnableShellCompletionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#EnableShellCompletion.: true, |
| 110 | Writerscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Writer.: out, |
| 111 | } |
| 112 | |
| 113 | r := requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Newscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/New().(t) |
| 114 | |
| 115 | r.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NoError().(cmd.Runscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Run().(buildTestContextscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/buildTestContext().(t), []string{"foo", completionCommandNamescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionCommandName., k})) |
| 116 | r.NotEmptyscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NotEmpty().(out.Stringscip-go gomod github.com/golang/go/src go1.22 bytes/Buffer#String().(), "Expected non-empty completion output for shell %q", k) |
| 117 | }) |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | func TestCompletionSubcommandOrderscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TestCompletionSubcommandOrder().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 122 | // The completion subcommands must appear in a deterministic order so that |
| 123 | // help output (and docs generated from it) does not change between runs. |
| 124 | // Previously they were built by iterating a map, whose order Go randomizes. |
| 125 | want := []string{"bash", "zsh", "fish", "pwsh"} |
| 126 | |
| 127 | // Build several times to guard against intra-process variation. |
| 128 | for range 10 { |
| 129 | cmd := buildCompletionCommandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/buildCompletionCommand().("foo") |
| 130 | |
| 131 | got := make([]string, 0, len(cmd.Commandsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Commands.)) |
| 132 | for _, sub := range cmd.Commandsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Commands. { |
| 133 | got = append(got, sub.Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Name.) |
| 134 | } |
| 135 | |
| 136 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, want, got) |
| 137 | } |
| 138 | |
| 139 | // Every shell in shellCompletions must be represented in the ordered list. |
| 140 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Lenscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Len().(t, completionShellsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionShells., len(shellCompletionsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/shellCompletions.)) |
| 141 | for shell := range shellCompletionsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/shellCompletions. { |
| 142 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Containsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Contains().(t, completionShellsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionShells., shell) |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | func TestCompletionBashNoShebangscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TestCompletionBashNoShebang().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 147 | // Regression test for https://github.com/urfave/cli/issues/2259 |
| 148 | // Bash completion scripts are sourced, not executed, so they must not |
| 149 | // start with a `#!` shebang (flagged by Debian lintian as |
| 150 | // `bash-completion-with-hashbang`). |
| 151 | |
| 152 | cmd := &Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 153 | EnableShellCompletionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#EnableShellCompletion.: true, |
| 154 | } |
| 155 | |
| 156 | r := requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Newscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/New().(t) |
| 157 | |
| 158 | bashRender := shellCompletionsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/shellCompletions.["bash"] |
| 159 | r.NotNilscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NotNil().(bashRender, "bash completion renderer should exist") |
| 160 | |
| 161 | output, err := bashRender(cmd, "myapp") |
| 162 | r.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NoError().(err) |
| 163 | r.NotEmptyscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NotEmpty().(output, "bash completion output should not be empty") |
| 164 | r.Falsescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#False().(stringsscip-go gomod github.com/golang/go/src go1.22 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.22 strings/HasPrefix().(output, "#!"), "bash completion should not start with a shebang") |
| 165 | } |
| 166 | |
| 167 | func TestCompletionBashAppendsSpacescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TestCompletionBashAppendsSpace().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 168 | // Regression test for https://github.com/urfave/cli/issues/2332 |
| 169 | // Do not register bash completions with `-o nospace`: after a command or |
| 170 | // subcommand completion, Bash should append a space so the next word can be |
| 171 | // completed without manually typing one. |
| 172 | |
| 173 | cmd := &Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 174 | EnableShellCompletionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#EnableShellCompletion.: true, |
| 175 | } |
| 176 | |
| 177 | r := requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Newscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/New().(t) |
| 178 | |
| 179 | bashRender := shellCompletionsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/shellCompletions.["bash"] |
| 180 | r.NotNilscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NotNil().(bashRender, "bash completion renderer should exist") |
| 181 | |
| 182 | output, err := bashRender(cmd, "myapp") |
| 183 | r.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NoError().(err) |
| 184 | r.NotContainsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NotContains().(output, "-o nospace", "bash completion should append spaces after completed words") |
| 185 | r.Containsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#Contains().(output, "complete -o bashdefault -o default -F __myapp_bash_autocomplete myapp") |
| 186 | } |
| 187 | |
| 188 | func TestCompletionBashGreedyColonParsingscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TestCompletionBashGreedyColonParsing().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 189 | // Regression test for https://github.com/urfave/cli/issues/2335 |
| 190 | // The bash completion template uses fmt.Sprintf, so |
| 191 | // literal "%" in the template must be escaped as "%%". The token |
| 192 | // extraction must use the greedy ${line%%:*} (double %%) to split on |
| 193 | // the *first* colon. A single % would use ${line%:*} which splits on |
| 194 | // the *last* colon, breaking descriptions that contain colons |
| 195 | // (e.g. "export:Export configs such as: compose-config"). |
| 196 | |
| 197 | cmd := &Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 198 | EnableShellCompletionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#EnableShellCompletion.: true, |
| 199 | } |
| 200 | |
| 201 | r := requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Newscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/New().(t) |
| 202 | |
| 203 | bashRender := shellCompletionsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/shellCompletions.["bash"] |
| 204 | r.NotNilscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NotNil().(bashRender, "bash completion renderer should exist") |
| 205 | |
| 206 | output, err := bashRender(cmd, "myapp") |
| 207 | r.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NoError().(err) |
| 208 | |
| 209 | // After fmt.Sprintf, the rendered script must contain ${line%%:*} |
| 210 | // (greedy match) not ${line%:*} (non-greedy match). |
| 211 | r.Containsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#Contains().(output, `${line%%:*}`, "token extraction should use greedy %% to match first colon") |
| 212 | r.NotContainsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NotContains().(output, `${line%:*}`, "token extraction must not use non-greedy single % (splits on last colon)") |
| 213 | } |
| 214 | |
| 215 | func TestCompletionFishFormatscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TestCompletionFishFormat().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 216 | // Regression test for https://github.com/urfave/cli/issues/2285 |
| 217 | // Fish completion was broken due to incorrect format specifiers |
| 218 | |
| 219 | cmd := &Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 220 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Name.: "myapp", |
| 221 | EnableShellCompletionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#EnableShellCompletion.: true, |
| 222 | } |
| 223 | |
| 224 | r := requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Newscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/New().(t) |
| 225 | |
| 226 | // Test the fish shell completion renderer directly |
| 227 | fishRender := shellCompletionsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/shellCompletions.["fish"] |
| 228 | r.NotNilscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NotNil().(fishRender, "fish completion renderer should exist") |
| 229 | |
| 230 | output, err := fishRender(cmd, "myapp") |
| 231 | r.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NoError().(err) |
| 232 | |
| 233 | // Verify the function name is correctly formatted |
| 234 | r.Containsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#Contains().(output, "function __myapp_perform_completion", "function name should contain app name") |
| 235 | |
| 236 | // Verify no format errors (like %! or (string=) which indicate broken fmt.Sprintf) |
| 237 | r.NotContainsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NotContains().(output, "%!", "output should not contain format errors") |
| 238 | r.NotContainsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NotContains().(output, "(string=", "output should not contain invalid fish syntax") |
| 239 | |
| 240 | // Verify the complete commands reference the app correctly |
| 241 | r.Containsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#Contains().(output, "complete -c myapp", "complete command should reference app name") |
| 242 | r.Containsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#Contains().(output, "(__myapp_perform_completion)", "completion function should be registered") |
| 243 | } |
| 244 | |
| 245 | func TestCompletionFishOmitsPositionalTokenFromDynamicCompletionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TestCompletionFishOmitsPositionalTokenFromDynamicCompletion().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 246 | cmd := &Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 247 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Name.: "myapp", |
| 248 | EnableShellCompletionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#EnableShellCompletion.: true, |
| 249 | } |
| 250 | |
| 251 | r := requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Newscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/New().(t) |
| 252 | |
| 253 | fishRender := shellCompletionsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/shellCompletions.["fish"] |
| 254 | r.NotNilscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NotNil().(fishRender, "fish completion renderer should exist") |
| 255 | |
| 256 | output, err := fishRender(cmd, "myapp") |
| 257 | r.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NoError().(err) |
| 258 | |
| 259 | r.Containsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#Contains().(output, `if string match -q -- "-*" $lastArg`) |
| 260 | r.Containsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#Contains().(output, "set results ($args[1] $args[2..-1] $lastArg --generate-shell-completion 2> /dev/null)") |
| 261 | r.Containsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#Contains().(output, "set results ($args[1] $args[2..-1] --generate-shell-completion 2> /dev/null)") |
| 262 | } |
| 263 | |
| 264 | func TestCompletionBashOmitsPositionalTokenFromDynamicCompletionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TestCompletionBashOmitsPositionalTokenFromDynamicCompletion().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 265 | cmd := &Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 266 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Name.: "myapp", |
| 267 | EnableShellCompletionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#EnableShellCompletion.: true, |
| 268 | } |
| 269 | |
| 270 | r := requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Newscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/New().(t) |
| 271 | |
| 272 | bashRender := shellCompletionsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/shellCompletions.["bash"] |
| 273 | r.NotNilscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NotNil().(bashRender, "bash completion renderer should exist") |
| 274 | |
| 275 | output, err := bashRender(cmd, "myapp") |
| 276 | r.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NoError().(err) |
| 277 | |
| 278 | r.Containsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#Contains().(output, `if [[ "${current_word}" == "-"* ]]; then`) |
| 279 | r.Containsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#Contains().(output, `printf '%s %s --generate-shell-completion' "${words_before_cursor[*]}" "${current_word}"`) |
| 280 | r.Containsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#Contains().(output, `printf '%s --generate-shell-completion' "${words_before_cursor[*]}"`) |
| 281 | } |
| 282 | |
| 283 | func TestCompletionSubcommandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TestCompletionSubcommand().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 284 | tests := []struct { |
| 285 | name string |
| 286 | args []string |
| 287 | contains string |
| 288 | msg string |
| 289 | msgArgs []any |
| 290 | notContains bool |
| 291 | }{ |
| 292 | { |
| 293 | name: "subcommand general completion", |
| 294 | args: []string{"foo", "bar", completionFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionFlag.}, |
| 295 | contains: "xyz", |
| 296 | msg: "Expected output to contain shell name %[1]q", |
| 297 | msgArgs: []any{ |
| 298 | "xyz", |
| 299 | }, |
| 300 | }, |
| 301 | { |
| 302 | name: "subcommand flag completion", |
| 303 | args: []string{"foo", "bar", "-", completionFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionFlag.}, |
| 304 | contains: "l1", |
| 305 | msg: "Expected output to contain shell name %[1]q", |
| 306 | msgArgs: []any{ |
| 307 | "l1", |
| 308 | }, |
| 309 | }, |
| 310 | { |
| 311 | name: "subcommand double dash shows long flags", |
| 312 | args: []string{"foo", "bar", "--", completionFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionFlag.}, |
| 313 | contains: "--l1", |
| 314 | msg: "Expected output to contain flag %[1]q", |
| 315 | msgArgs: []any{ |
| 316 | "--l1", |
| 317 | }, |
| 318 | }, |
| 319 | { |
| 320 | name: "sub sub command general completion", |
| 321 | args: []string{"foo", "bar", "xyz", completionFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionFlag.}, |
| 322 | contains: "-g", |
| 323 | msg: "Expected output to contain flag %[1]q", |
| 324 | msgArgs: []any{ |
| 325 | "-g", |
| 326 | }, |
| 327 | notContains: true, |
| 328 | }, |
| 329 | { |
| 330 | name: "sub sub command flag completion", |
| 331 | args: []string{"foo", "bar", "xyz", "-", completionFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionFlag.}, |
| 332 | contains: "-g", |
| 333 | msg: "Expected output to contain flag %[1]q", |
| 334 | msgArgs: []any{ |
| 335 | "-g", |
| 336 | }, |
| 337 | }, |
| 338 | { |
| 339 | name: "sub sub command double dash shows flags", |
| 340 | args: []string{"foo", "bar", "xyz", "--", completionFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionFlag.}, |
| 341 | contains: "--help", |
| 342 | msg: "Expected output to contain flag %[1]q", |
| 343 | msgArgs: []any{ |
| 344 | "--help", |
| 345 | }, |
| 346 | }, |
| 347 | { |
| 348 | name: "sub sub command no completion extra args", |
| 349 | args: []string{"foo", "bar", "xyz", "--", "sargs", completionFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionFlag.}, |
| 350 | contains: "-g", |
| 351 | msg: "Expected output to contain flag %[1]q", |
| 352 | msgArgs: []any{ |
| 353 | "-g", |
| 354 | }, |
| 355 | notContains: true, |
| 356 | }, |
| 357 | { |
| 358 | name: "subcommand partial double dash flag completion", |
| 359 | args: []string{"foo", "bar", "--l", completionFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionFlag.}, |
| 360 | contains: "--l1", |
| 361 | msg: "Expected output to contain flag %[1]q", |
| 362 | msgArgs: []any{ |
| 363 | "--l1", |
| 364 | }, |
| 365 | }, |
| 366 | { |
| 367 | name: "sub sub command partial double dash flag completion", |
| 368 | args: []string{"foo", "bar", "xyz", "--he", completionFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionFlag.}, |
| 369 | contains: "--help", |
| 370 | msg: "Expected output to contain flag %[1]q", |
| 371 | msgArgs: []any{ |
| 372 | "--help", |
| 373 | }, |
| 374 | }, |
| 375 | } |
| 376 | |
| 377 | for _, test := range tests { |
| 378 | t.Runscip-go gomod github.com/golang/go/src go1.22 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 379 | out := &bytesscip-go gomod github.com/golang/go/src go1.22 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.22 bytes/Buffer#{} |
| 380 | |
| 381 | cmd := &Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 382 | EnableShellCompletionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#EnableShellCompletion.: true, |
| 383 | Writerscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Writer.: out, |
| 384 | Commandsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Commands.: []*Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 385 | { |
| 386 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Name.: "bar", |
| 387 | Flagsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Flags.: []Flagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Flag#{ |
| 388 | &StringFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/StringFlag#{ |
| 389 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/FlagBase#Name.: "l1", |
| 390 | }, |
| 391 | }, |
| 392 | Actionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Action.: func(ctx contextscip-go gomod github.com/golang/go/src go1.22 context/.Contextscip-go gomod github.com/golang/go/src go1.22 context/Context#, c *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#) error { return nil }, |
| 393 | Commandsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Commands.: []*Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 394 | { |
| 395 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Name.: "xyz", |
| 396 | Flagsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Flags.: []Flagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Flag#{ |
| 397 | &StringFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/StringFlag#{ |
| 398 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/FlagBase#Name.: "g", |
| 399 | Aliasesscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/FlagBase#Aliases.: []string{ |
| 400 | "t", |
| 401 | }, |
| 402 | }, |
| 403 | }, |
| 404 | Actionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Action.: func(ctx contextscip-go gomod github.com/golang/go/src go1.22 context/.Contextscip-go gomod github.com/golang/go/src go1.22 context/Context#, c *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#) error { return nil }, |
| 405 | }, |
| 406 | }, |
| 407 | }, |
| 408 | }, |
| 409 | } |
| 410 | |
| 411 | r := requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Newscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/New().(t) |
| 412 | |
| 413 | r.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NoError().(cmd.Runscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Run().(buildTestContextscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/buildTestContext().(t), test.args)) |
| 414 | if test.notContains { |
| 415 | r.NotContainsfscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NotContainsf().(out.Stringscip-go gomod github.com/golang/go/src go1.22 bytes/Buffer#String().(), test.contains, test.msg, test.msgArgs...) |
| 416 | } else { |
| 417 | r.Containsfscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#Containsf().(out.Stringscip-go gomod github.com/golang/go/src go1.22 bytes/Buffer#String().(), test.contains, test.msg, test.msgArgs...) |
| 418 | } |
| 419 | }) |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | func TestCompletionSubcommandCustomShellCompletescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TestCompletionSubcommandCustomShellComplete().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 424 | out := &bytesscip-go gomod github.com/golang/go/src go1.22 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.22 bytes/Buffer#{} |
| 425 | |
| 426 | cmd := &Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 427 | EnableShellCompletionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#EnableShellCompletion.: true, |
| 428 | Writerscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Writer.: out, |
| 429 | Commandsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Commands.: []*Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 430 | { |
| 431 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Name.: "index", |
| 432 | Commandsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Commands.: []*Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 433 | { |
| 434 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Name.: "show", |
| 435 | ShellCompletescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#ShellComplete.: func(ctx contextscip-go gomod github.com/golang/go/src go1.22 context/.Contextscip-go gomod github.com/golang/go/src go1.22 context/Context#, cmd *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#) { |
| 436 | fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Fprintlnscip-go gomod github.com/golang/go/src go1.22 fmt/Fprintln().(cmd.Rootscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Root().().Writerscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Writer., "custom-index") |
| 437 | }, |
| 438 | Actionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Action.: func(ctx contextscip-go gomod github.com/golang/go/src go1.22 context/.Contextscip-go gomod github.com/golang/go/src go1.22 context/Context#, cmd *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#) error { return nil }, |
| 439 | }, |
| 440 | }, |
| 441 | }, |
| 442 | }, |
| 443 | } |
| 444 | |
| 445 | r := requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Newscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/New().(t) |
| 446 | r.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NoError().(cmd.Runscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Run().(buildTestContextscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/buildTestContext().(t), []string{"foo", "index", "show", completionFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionFlag.})) |
| 447 | r.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#Equal().("custom-index\n", out.Stringscip-go gomod github.com/golang/go/src go1.22 bytes/Buffer#String().()) |
| 448 | } |
| 449 | |
| 450 | func TestCompletionRunsBeforeChainscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TestCompletionRunsBeforeChain().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 451 | type contextKey struct{} |
| 452 | |
| 453 | out := &bytesscip-go gomod github.com/golang/go/src go1.22 bytes/.Bufferscip-go gomod github.com/golang/go/src go1.22 bytes/Buffer#{} |
| 454 | cmd := &Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 455 | EnableShellCompletionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#EnableShellCompletion.: true, |
| 456 | Writerscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Writer.: out, |
| 457 | Beforescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Before.: func(ctx contextscip-go gomod github.com/golang/go/src go1.22 context/.Contextscip-go gomod github.com/golang/go/src go1.22 context/Context#, cmd *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#) (contextscip-go gomod github.com/golang/go/src go1.22 context/.Contextscip-go gomod github.com/golang/go/src go1.22 context/Context#, error) { |
| 458 | return contextscip-go gomod github.com/golang/go/src go1.22 context/.WithValuescip-go gomod github.com/golang/go/src go1.22 context/WithValue().(ctx, contextKey{}, "ready"), nil |
| 459 | }, |
| 460 | Commandsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Commands.: []*Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 461 | { |
| 462 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Name.: "index", |
| 463 | Commandsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Commands.: []*Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 464 | { |
| 465 | Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Name.: "show", |
| 466 | ShellCompletescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#ShellComplete.: func(ctx contextscip-go gomod github.com/golang/go/src go1.22 context/.Contextscip-go gomod github.com/golang/go/src go1.22 context/Context#, cmd *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#) { |
| 467 | fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Fprintlnscip-go gomod github.com/golang/go/src go1.22 fmt/Fprintln().(cmd.Rootscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Root().().Writerscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Writer., ctx.Valuescip-go gomod github.com/golang/go/src go1.22 context/Context#Value().(contextKey{})) |
| 468 | }, |
| 469 | Actionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Action.: func(ctx contextscip-go gomod github.com/golang/go/src go1.22 context/.Contextscip-go gomod github.com/golang/go/src go1.22 context/Context#, cmd *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#) error { return nil }, |
| 470 | }, |
| 471 | }, |
| 472 | }, |
| 473 | }, |
| 474 | } |
| 475 | |
| 476 | r := requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Newscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/New().(t) |
| 477 | r.NoErrorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#NoError().(cmd.Runscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Run().(buildTestContextscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/buildTestContext().(t), []string{"foo", "index", "show", completionFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionFlag.})) |
| 478 | r.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Assertions#Equal().("ready\n", out.Stringscip-go gomod github.com/golang/go/src go1.22 bytes/Buffer#String().()) |
| 479 | } |
| 480 | |
| 481 | func TestCompletionReturnsBeforeErrorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TestCompletionReturnsBeforeError().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 482 | beforeErr := errorsscip-go gomod github.com/golang/go/src go1.22 errors/.Newscip-go gomod github.com/golang/go/src go1.22 errors/New().("load config") |
| 483 | completed := false |
| 484 | |
| 485 | cmd := &Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 486 | EnableShellCompletionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#EnableShellCompletion.: true, |
| 487 | Writerscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Writer.: ioscip-go gomod github.com/golang/go/src go1.22 io/.Discardscip-go gomod github.com/golang/go/src go1.22 io/Discard., |
| 488 | Beforescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Before.: func(ctx contextscip-go gomod github.com/golang/go/src go1.22 context/.Contextscip-go gomod github.com/golang/go/src go1.22 context/Context#, cmd *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#) (contextscip-go gomod github.com/golang/go/src go1.22 context/.Contextscip-go gomod github.com/golang/go/src go1.22 context/Context#, error) { |
| 489 | return nil, beforeErr |
| 490 | }, |
| 491 | ShellCompletescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#ShellComplete.: func(ctx contextscip-go gomod github.com/golang/go/src go1.22 context/.Contextscip-go gomod github.com/golang/go/src go1.22 context/Context#, cmd *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#) { |
| 492 | completed = true |
| 493 | }, |
| 494 | } |
| 495 | |
| 496 | err := cmd.Runscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Run().(buildTestContextscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/buildTestContext().(t), []string{"foo", completionFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionFlag.}) |
| 497 | |
| 498 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.ErrorIsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/ErrorIs().(t, err, beforeErr) |
| 499 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Falsescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/False().(t, completed) |
| 500 | } |
| 501 | |
| 502 | func TestCompletionInvalidShellscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TestCompletionInvalidShell().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 503 | cmd := &Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 504 | EnableShellCompletionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#EnableShellCompletion.: true, |
| 505 | } |
| 506 | |
| 507 | unknownShellName := "junky-sheell" |
| 508 | err := cmd.Runscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Run().(buildTestContextscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/buildTestContext().(t), []string{"foo", completionCommandNamescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionCommandName., unknownShellName}) |
| 509 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.ErrorContainsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/ErrorContains().(t, err, fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.22 fmt/Sprintf().("No help topic for '%s'", unknownShellName)) |
| 510 | } |
| 511 | |
| 512 | func TestCompletionShellRenderErrorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TestCompletionShellRenderError().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 513 | unknownShellName := "junky-sheell" |
| 514 | |
| 515 | enableError := true |
| 516 | shellCompletionsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/shellCompletions.[unknownShellName] = func(c *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#, appName string) (string, error) { |
| 517 | if enableError { |
| 518 | return "", fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.22 fmt/Errorf().("can't do completion") |
| 519 | } |
| 520 | return "something", nil |
| 521 | } |
| 522 | // buildCompletionCommand only turns shells listed in completionShells into |
| 523 | // subcommands, so register the injected shell there too (restoring the |
| 524 | // original slice afterward) for it to be reachable. |
| 525 | defer func(orig []string) { completionShellsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionShells. = orig }(completionShellsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionShells.) |
| 526 | completionShellsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionShells. = append(completionShellsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionShells., unknownShellName) |
| 527 | defer func() { |
| 528 | delete(shellCompletionsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/shellCompletions., unknownShellName) |
| 529 | }() |
| 530 | |
| 531 | cmd := &Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 532 | EnableShellCompletionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#EnableShellCompletion.: true, |
| 533 | } |
| 534 | |
| 535 | err := cmd.Runscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Run().(buildTestContextscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/buildTestContext().(t), []string{"foo", completionCommandNamescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionCommandName., unknownShellName}) |
| 536 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.ErrorContainsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/ErrorContains().(t, err, "can't do completion") |
| 537 | } |
| 538 | |
| 539 | type mockWriterscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/mockWriter# struct { |
| 540 | errscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/mockWriter#err. error |
| 541 | } |
| 542 | |
| 543 | func (mw *mockWriterscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/mockWriter#) Writescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/mockWriter#Write().(p []byte) (int, error) { |
| 544 | if mw.errscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/mockWriter#err. != nil { |
| 545 | return 0, mw.errscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/mockWriter#err. |
| 546 | } |
| 547 | return len(p), nil |
| 548 | } |
| 549 | |
| 550 | func TestCompletionShellWriteErrorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TestCompletionShellWriteError().(t *testingscip-go gomod github.com/golang/go/src go1.22 testing/.Tscip-go gomod github.com/golang/go/src go1.22 testing/T#) { |
| 551 | shellName := "mock-shell" |
| 552 | shellCompletionsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/shellCompletions.[shellName] = func(c *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#, appName string) (string, error) { |
| 553 | return "something", nil |
| 554 | } |
| 555 | // buildCompletionCommand only turns shells listed in completionShells into |
| 556 | // subcommands, so register the injected shell there too (restoring the |
| 557 | // original slice afterward) for it to be reachable. |
| 558 | defer func(orig []string) { completionShellsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionShells. = orig }(completionShellsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionShells.) |
| 559 | completionShellsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionShells. = append(completionShellsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionShells., shellName) |
| 560 | defer func() { |
| 561 | delete(shellCompletionsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/shellCompletions., shellName) |
| 562 | }() |
| 563 | |
| 564 | cmd := &Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#{ |
| 565 | EnableShellCompletionscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#EnableShellCompletion.: true, |
| 566 | Writerscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Writer.: &mockWriterscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/mockWriter#{errscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/mockWriter#err.: fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.22 fmt/Errorf().("writer error")}, |
| 567 | } |
| 568 | |
| 569 | err := cmd.Runscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Run().(buildTestContextscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/buildTestContext().(t), []string{"foo", completionCommandNamescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/completionCommandName., shellName}) |
| 570 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.ErrorContainsscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/ErrorContains().(t, err, "writer error") |
| 571 | } |