Skip to content

Commit 83da8d2

Browse files
fix(deps): update module github.com/alecthomas/kong to v1 (#397)
1 parent 900b811 commit 83da8d2

File tree

5 files changed

+69
-11
lines changed

5 files changed

+69
-11
lines changed

dumpmd.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,15 @@ func (cmd cliDumper) dumpFlag(flag *kong.Flag) {
237237

238238
// long flag
239239
cmd.print("`--")
240-
if flag.IsBool() && flag.Tag.Negatable {
241-
cmd.print("[no-]")
240+
if flag.IsBool() && flag.Tag.Negatable != "" {
241+
// Value is "_" for "--no-<flag>",
242+
// and anything else for "--<neg>".
243+
if flag.Tag.Negatable == "_" {
244+
cmd.print("[no-]")
245+
} else {
246+
// Don't need this yet, so don't bother.
247+
panic("not yet implemented")
248+
}
242249
}
243250
cmd.print(name)
244251
// =value

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module go.abhg.dev/gs
33
go 1.23
44

55
require (
6-
github.com/alecthomas/kong v0.9.0
6+
github.com/alecthomas/kong v1.2.1
77
github.com/buildkite/shellwords v0.0.0-20180315110454-59467a9b8e10
88
github.com/charmbracelet/bubbles v0.20.0
99
github.com/charmbracelet/bubbletea v1.1.1

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
github.com/alecthomas/assert/v2 v2.6.0 h1:o3WJwILtexrEUk3cUVal3oiQY2tfgr/FHWiz/v2n4FU=
2-
github.com/alecthomas/assert/v2 v2.6.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
3-
github.com/alecthomas/kong v0.9.0 h1:G5diXxc85KvoV2f0ZRVuMsi45IrBgx9zDNGNj165aPA=
4-
github.com/alecthomas/kong v0.9.0/go.mod h1:Y47y5gKfHp1hDc7CH7OeXgLIpp+Q2m1Ni0L5s3bI8Os=
1+
github.com/alecthomas/assert/v2 v2.10.0 h1:jjRCHsj6hBJhkmhznrCzoNpbA3zqy0fYiUcYZP/GkPY=
2+
github.com/alecthomas/assert/v2 v2.10.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
3+
github.com/alecthomas/kong v1.2.1 h1:E8jH4Tsgv6wCRX2nGrdPyHDUCSG83WH2qE4XLACD33Q=
4+
github.com/alecthomas/kong v1.2.1/go.mod h1:rKTSFhbdp3Ryefn8x5MOEprnRFQ7nlmMC01GKhehhBM=
55
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
66
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
77
github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0=

internal/komplete/komplete.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,8 @@ func (k *kongPredictor) matchFlag(flags []*kong.Flag, scan *kong.Scanner, arg st
529529
matched = "-"+string(flag.Short) == arg
530530
}
531531

532-
if !matched && flag.Tag.Negatable {
533-
matched = "--no-"+flag.Name == arg
532+
if negFlag := negatableFlagName(flag); !matched && negFlag != "" {
533+
matched = negFlag == arg
534534
}
535535

536536
if !matched {
@@ -632,8 +632,8 @@ func (p *flagsPredictor) Predict(cargs Args) (predictions []string) {
632632
}
633633

634634
predictions = append(predictions, "--"+flag.Name)
635-
if flag.Tag.Negatable {
636-
predictions = append(predictions, "--no-"+flag.Name)
635+
if negFlag := negatableFlagName(flag); negFlag != "" {
636+
predictions = append(predictions, negFlag)
637637
}
638638

639639
// Include aliases only if the user has typed a prefix.
@@ -664,3 +664,16 @@ func (p *prefixPredictor) Predict(cargs Args) (predictions []string) {
664664
}
665665
return newPredictions
666666
}
667+
668+
func negatableFlagName(f *kong.Flag) string {
669+
// Kong uses "_" as a placeholder for "--no-<flag>".
670+
// Any other value means the flag is "--<negation>".
671+
switch f.Tag.Negatable {
672+
case "":
673+
return ""
674+
case "_":
675+
return "--no-" + f.Name
676+
default:
677+
return "--" + f.Tag.Negatable
678+
}
679+
}

internal/komplete/komplete_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,44 @@ func TestKongPredictor(t *testing.T) {
282282
},
283283
},
284284
},
285+
{
286+
name: "negation/default",
287+
grammar: &struct {
288+
Spicy bool `negatable:""` // --spicy, --no-spicy
289+
}{},
290+
cases: []completeCase{
291+
{
292+
want: []string{"--help", "--spicy", "--no-spicy"},
293+
},
294+
{
295+
give: compLine("--s"),
296+
want: []string{"--spicy"},
297+
},
298+
{
299+
give: compLine("--n"),
300+
want: []string{"--no-spicy"},
301+
},
302+
},
303+
},
304+
{
305+
name: "negation/custom",
306+
grammar: &struct {
307+
Spicy bool `negatable:"mild"` // --spicy, --mild
308+
}{},
309+
cases: []completeCase{
310+
{
311+
want: []string{"--help", "--spicy", "--mild"},
312+
},
313+
{
314+
give: compLine("--s"),
315+
want: []string{"--spicy"},
316+
},
317+
{
318+
give: compLine("--m"),
319+
want: []string{"--mild"},
320+
},
321+
},
322+
},
285323
}
286324

287325
for _, tt := range tests {

0 commit comments

Comments
 (0)