Skip to content
Myr

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

1 file+5 added−30 removed

modified:command.go+5 added-30 removed
108 unmodified lines
109 commandsMaxNameLen int110 // is commands slice are sorted or not111 commandsAreSorted bool112113 flagErrorBuf *bytes.Buffer114113 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 Application
554 unmodified lines
671 x()672 }673}674677func (c *Command) errorMsgFromParse() string {678 s := c.flagErrorBuf.String()679680 x := strings.Split(s, "\n")681682 if len(x) > 0 {683 return x[0]684 }685 return ""686}687675// 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.678func (c *Command) Execute() error {
255 unmodified lines
934 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 lines
1074// to this command (local and persistent declared here and by all parents).1075func (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 lines
1148// PersistentFlags returns the persistent FlagSet specifically set in the current command.1149func (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}11561157// ResetFlags is used in testing.1158func (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}11641165// HasFlags checks if the command contains any flags (local plus persistent from the entire structure).1166func (c *Command) HasFlags() bool {
81 unmodified lines
12481249 // 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