From 47d0a68daf57b0ff3e44a19f59eb66aae5b4e3d8 Mon Sep 17 00:00:00 2001 From: maxlandon Date: Mon, 15 May 2023 07:01:45 +0200 Subject: [PATCH] Recommit correct configuration file load --- complete.go | 4 ++++ internal/shell/spec/snippet.go | 2 -- internalActions.go | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/complete.go b/complete.go index 62367b6c2..ed1867a3e 100644 --- a/complete.go +++ b/complete.go @@ -20,6 +20,10 @@ func Complete(cmd *cobra.Command, args []string, onFinalize func()) (common.RawV // action, current := generate(cmd, args) action, context := traverse(cmd, args[2:]) + if err := config.Load(); err != nil { + action = ActionMessage("failed to load config: " + err.Error()) + } + invoked := action.Invoke(context) // And adapt/fetch the results from invoked action diff --git a/internal/shell/spec/snippet.go b/internal/shell/spec/snippet.go index d34e2d68b..b60d6180e 100644 --- a/internal/shell/spec/snippet.go +++ b/internal/shell/spec/snippet.go @@ -31,7 +31,6 @@ func command(cmd *cobra.Command) Command { } f := pflagfork.Flag{Flag: flag} c.Flags[f.Definition()] = f.Usage - }) cmd.PersistentFlags().VisitAll(func(flag *pflag.Flag) { @@ -40,7 +39,6 @@ func command(cmd *cobra.Command) Command { } f := pflagfork.Flag{Flag: flag} c.PersistentFlags[f.Definition()] = f.Usage - }) for _, subcmd := range cmd.Commands() { diff --git a/internalActions.go b/internalActions.go index b0cd9d410..bde5b1ed2 100644 --- a/internalActions.go +++ b/internalActions.go @@ -73,6 +73,8 @@ func actionFlags(cmd *cobra.Command) Action { flagSet := pflagfork.FlagSet{FlagSet: cmd.Flags()} isShorthandSeries := flagSet.IsShorthandSeries(c.Value) + needsMultipart := false + vals := make([]string, 0) flagSet.VisitAll(func(f *pflagfork.Flag) { switch { @@ -104,13 +106,25 @@ func actionFlags(cmd *cobra.Command) Action { if f.Shorthand != "" && f.ShorthandDeprecated == "" { vals = append(vals, "-"+f.Shorthand, f.Usage, f.Style()) } + + if strings.Contains(f.Name, ".") { + needsMultipart = true + } } }) if isShorthandSeries { return ActionStyledValuesDescribed(vals...).Prefix(c.Value).NoSpace('*') } - return ActionStyledValuesDescribed(vals...).MultiParts(".") // multiparts completion for flags grouped with `.` + + action := ActionStyledValuesDescribed(vals...) + + // multiparts completion for flags grouped with `.` + if needsMultipart { + action = action.MultiParts(".") + } + + return action }).Tag("flags") }