Skip to content
Myr

Revert "Get rid of flagErrorBuf (#417)"

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This reverts commit b655df6ce84126fe9272a3cd4d70555a3a4cfed4. Reason for revert: duplicate errors from flag. More in #426 Fix #426

authored by Albert Nigmatzianov · committed by Albert Nigmatzianov · parent 6dd9084 · Browse files · 1 file+25 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+25 added−6 removed

  • other:+25 added−6 removed

1 file+25 added−6 removed

modified:command.go+25 added-6 removed
112 unmodified lines
113 commandsMaxNameLen int114 // is commands slice are sorted or not115 commandsAreSorted bool116117 // flagErrorBuf contains all error messages from pflag.118 flagErrorBuf *bytes.Buffer119120 args []string // actual args parsed from flags121 output io.Writer // out writer if set in SetOutput(w)122 usageFunc func(*Command) error // Usage can be defined by application123 usageTemplate string // Can be defined by Application
793 unmodified lines
917 c.Println(" -"+f.Shorthand+",", "--"+f.Name, "["+f.DefValue+"]", "", f.Value, " [P]")918 }919 })920 }921 c.Println(x.flagErrorBuf)922 if x.HasSubCommands() {923 for _, y := range x.commands {924 debugflags(y)925 }
132 unmodified lines
1058// to this command (local and persistent declared here and by all parents).1059func (c *Command) Flags() *flag.FlagSet {1060 if c.flags == nil {1061 c.flags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)1062 if c.flagErrorBuf == nil {1063 c.flagErrorBuf = new(bytes.Buffer)1064 }1058 c.flags.SetOutput(c.OutOrStderr())1065 c.flags.SetOutput(c.flagErrorBuf)1066 }10671068 return c.flags1069}
16 unmodified lines
1086 c.mergePersistentFlags()10871088 if c.lflags == nil {1089 c.lflags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)1090 if c.flagErrorBuf == nil {1091 c.flagErrorBuf = new(bytes.Buffer)1092 }1083 c.lflags.SetOutput(c.OutOrStderr())1093 c.lflags.SetOutput(c.flagErrorBuf)1094 }1095 c.lflags.SortFlags = c.Flags().SortFlags10961097 addToLocal := func(f *flag.Flag) {
11 unmodified lines
1109 c.mergePersistentFlags()11101111 if c.iflags == nil {1112 c.iflags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)1113 if c.flagErrorBuf == nil {1114 c.flagErrorBuf = new(bytes.Buffer)1115 }1116 c.iflags.SetOutput(c.flagErrorBuf)1117 }11181119 local := c.LocalFlags()1120 c.parentsPflags.VisitAll(func(f *flag.Flag) {
12 unmodified lines
1133// PersistentFlags returns the persistent FlagSet specifically set in the current command.1134func (c *Command) PersistentFlags() *flag.FlagSet {1135 if c.pflags == nil {1136 c.pflags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)1137 if c.flagErrorBuf == nil {1138 c.flagErrorBuf = new(bytes.Buffer)1139 }1123 c.pflags.SetOutput(c.OutOrStderr())1140 c.pflags.SetOutput(c.flagErrorBuf)1141 }1142 return c.pflags1143}11441145// ResetFlags is used in testing.1146func (c *Command) ResetFlags() {1147 c.flagErrorBuf = new(bytes.Buffer)1148 c.flagErrorBuf.Reset()1149 c.flags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)1131 c.flags.SetOutput(c.OutOrStderr())1150 c.flags.SetOutput(c.flagErrorBuf)1151 c.pflags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)1133 c.pflags.SetOutput(c.OutOrStderr())1152 c.pflags.SetOutput(c.flagErrorBuf)1153}11541155// HasFlags checks if the command contains any flags (local plus persistent from the entire structure).1156func (c *Command) HasFlags() bool {
90 unmodified lines
1247// If c.parentsPflags == nil, it makes new.1248func (c *Command) updateParentsPflags() {1249 if c.parentsPflags == nil {1250 c.parentsPflags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)1232 c.parentsPflags.SetOutput(c.OutOrStderr())1251 c.parentsPflags.SetOutput(c.flagErrorBuf)1252 c.parentsPflags.SortFlags = false1253 }12541255 c.Root().PersistentFlags().AddFlagSet(flag.CommandLine)
5 unmodified lines