Get rid of flagErrorBuf (#417)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Fix #27
authored by Albert Nigmatzianov · committed by Eric Paris · parent f95d58b · Browse files · 1 file·+5 added−30 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+5 added−30 removed
- other:+5 added−30 removed
Provenance
- Commit
b655df6- Tree
2cbb1f0- Author
Albert Nigmatzianov <albertnigma@gmail.com>- Committer
Eric Paris <eparis@redhat.com>- Parent
f95d58b
1 file changed+5 added−30 removed
modified:command.go+5 added-30 removed
108 unmodified lines109 commandsMaxNameLen int110 // is commands slice are sorted or not111 commandsAreSorted bool112 113- flagErrorBuf *bytes.Buffer114-113 args []string // actual args parsed from flags114 output io.Writer // out writer if set in SetOutput(w)115 usageFunc func(*Command) error // Usage can be defined by application116 usageTemplate string // Can be defined by Application554 unmodified lines671 x()672 }673 }674 677-func (c *Command) errorMsgFromParse() string {678- s := c.flagErrorBuf.String()679-680- x := strings.Split(s, "\n")681-682- if len(x) > 0 {683- return x[0]684- }685- return ""686-}687-675 // Execute Call execute to use the args (os.Args[1:] by default)676 // and run through the command tree finding appropriate matches677 // for commands and then corresponding flags.678 func (c *Command) Execute() error {255 unmodified lines934 c.Println(" -"+f.Shorthand+",", "--"+f.Name, "["+f.DefValue+"]", "", f.Value, " [P]")935 }936 })937 }951- c.Println(x.flagErrorBuf)938 if x.HasSubCommands() {939 for _, y := range x.commands {940 debugflags(y)941 }132 unmodified lines1074 // to this command (local and persistent declared here and by all parents).1075 func (c *Command) Flags() *flag.FlagSet {1076 if c.flags == nil {1077 c.flags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)1092- if c.flagErrorBuf == nil {1093- c.flagErrorBuf = new(bytes.Buffer)1094- }1095- c.flags.SetOutput(c.flagErrorBuf)1078+ c.flags.SetOutput(c.OutOrStderr())1079 }1080 return c.flags1081 }1082 65 unmodified lines1148 // PersistentFlags returns the persistent FlagSet specifically set in the current command.1149 func (c *Command) PersistentFlags() *flag.FlagSet {1150 if c.pflags == nil {1151 c.pflags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)1169- if c.flagErrorBuf == nil {1170- c.flagErrorBuf = new(bytes.Buffer)1171- }1172- c.pflags.SetOutput(c.flagErrorBuf)1152+ c.pflags.SetOutput(c.OutOrStderr())1153 }1154 return c.pflags1155 }1156 1157 // ResetFlags is used in testing.1158 func (c *Command) ResetFlags() {1179- c.flagErrorBuf = new(bytes.Buffer)1180- c.flagErrorBuf.Reset()1159 c.flags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)1182- c.flags.SetOutput(c.flagErrorBuf)1160+ c.flags.SetOutput(c.OutOrStderr())1161 c.pflags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)1184- c.pflags.SetOutput(c.flagErrorBuf)1162+ c.pflags.SetOutput(c.OutOrStderr())1163 }1164 1165 // HasFlags checks if the command contains any flags (local plus persistent from the entire structure).1166 func (c *Command) HasFlags() bool {81 unmodified lines1248 1249 // Save the set of local flags1250 if c.lflags == nil {1251 c.lflags = flag.NewFlagSet(c.Name(), flag.ContinueOnError)1274- if c.flagErrorBuf == nil {1275- c.flagErrorBuf = new(bytes.Buffer)1276- }1277- c.lflags.SetOutput(c.flagErrorBuf)1252+ c.lflags.SetOutput(c.OutOrStderr())1253 addtolocal := func(f *flag.Flag) {1254 c.lflags.AddFlag(f)1255 }1256 c.Flags().VisitAll(addtolocal)24 unmodified lines