@@ -441,10 +441,11 @@ func (o *Command) Selector(short string, long string, options []string, opts *Op
441
441
return & result
442
442
}
443
443
444
- // message2String - puts msg in result string
444
+ // message2String puts msg in result string
445
+ // done boolean indicates if result is ready to be returned
445
446
// Accepts an interface that can be error, string or fmt.Stringer that will be prepended to a message.
446
447
// All other interface types will be ignored
447
- func message2String (msg interface {}) string {
448
+ func message2String (msg interface {}) ( string , bool ) {
448
449
var result string
449
450
if msg != nil {
450
451
switch msg .(type ) {
@@ -453,7 +454,7 @@ func message2String(msg interface{}) string {
453
454
if msg .(subCommandError ).cmd != nil {
454
455
result += msg .(subCommandError ).cmd .Usage (nil )
455
456
}
456
- return result
457
+ return result , true
457
458
case error :
458
459
result = fmt .Sprintf ("%s\n " , msg .(error ).Error ())
459
460
case string :
@@ -462,7 +463,7 @@ func message2String(msg interface{}) string {
462
463
result = fmt .Sprintf ("%s\n " , msg .(fmt.Stringer ).String ())
463
464
}
464
465
}
465
- return result
466
+ return result , false
466
467
}
467
468
468
469
// getPrecedingCommands - collects info on command chain from root to current (o *Command) and all arguments in this chain
@@ -611,16 +612,18 @@ func (o *Command) Usage(msg interface{}) string {
611
612
}
612
613
}
613
614
614
- var result string
615
615
// Stay classy
616
616
maxWidth := 80
617
617
// List of arguments from all preceding commands
618
618
arguments := make ([]* arg , 0 )
619
619
// Line of commands until root
620
620
var chain []string
621
621
622
- // Put message in resultz
623
- result = message2String (msg )
622
+ // Put message in result
623
+ result , done := message2String (msg )
624
+ if done {
625
+ return result
626
+ }
624
627
625
628
//collect info about Preceding Commands into chain and arguments
626
629
o .getPrecedingCommands (& chain , & arguments )
0 commit comments