@@ -605,7 +605,20 @@ func CompleteAppConfig(config *newcmd.AppConfig, f *clientcmd.Factory, c *cobra.
605605
606606 unknown := config .AddArguments (args )
607607 if len (unknown ) != 0 {
608- return kcmdutil .UsageErrorf (c , "Did not recognize the following arguments: %v" , unknown )
608+ buf := & bytes.Buffer {}
609+ fmt .Fprintf (buf , "Did not recognize the following arguments: %v\n \n " , unknown )
610+ for argName , classErrs := range config .ComponentInputClassificationErrors {
611+ fmt .Fprintf (buf , "%s:\n " , argName )
612+ for _ , classErr := range classErrs {
613+ if classErr .Value != nil {
614+ fmt .Fprintf (buf , fmt .Sprintf ("%s: %v\n " , classErr .Key , classErr .Value ))
615+ } else {
616+ fmt .Fprintf (buf , fmt .Sprintf ("%s\n " , classErr .Key ))
617+ }
618+ }
619+ fmt .Fprintln (buf )
620+ }
621+ return kcmdutil .UsageErrorf (c , heredoc .Docf (buf .String ()))
609622 }
610623
611624 if config .AllowMissingImages && config .AsSearch {
@@ -701,7 +714,7 @@ func retryBuildConfig(info *resource.Info, err error) runtime.Object {
701714 return nil
702715}
703716
704- func handleError (err error , baseName , commandName , commandPath string , config * newcmd.AppConfig , transformError func (err error , baseName , commandName , commandPath string , groups errorGroups )) error {
717+ func handleError (err error , baseName , commandName , commandPath string , config * newcmd.AppConfig , transformError func (err error , baseName , commandName , commandPath string , groups errorGroups , config * newcmd. AppConfig )) error {
705718 if err == nil {
706719 return nil
707720 }
@@ -711,23 +724,19 @@ func handleError(err error, baseName, commandName, commandPath string, config *n
711724 }
712725 groups := errorGroups {}
713726 for _ , err := range errs {
714- transformError (err , baseName , commandName , commandPath , groups )
727+ transformError (err , baseName , commandName , commandPath , groups , config )
715728 }
716729 buf := & bytes.Buffer {}
717- if len (config .ArgumentClassificationErrors ) > 0 {
718- fmt .Fprintf (buf , "Errors occurred while determining argument types:\n " )
719- for _ , classErr := range config .ArgumentClassificationErrors {
720- fmt .Fprintf (buf , fmt .Sprintf ("\n %s: %v\n " , classErr .Key , classErr .Value ))
721- }
722- fmt .Fprint (buf , "\n " )
723- // this print serves as a header for the printing of the errorGroups, but
724- // only print it if we precede with classification errors, to help distinguish
725- // between the two
726- fmt .Fprintln (buf , "Errors occurred during resource creation:" )
727- }
728730 for _ , group := range groups {
729731 fmt .Fprint (buf , kcmdutil .MultipleErrors ("error: " , group .errs ))
732+ if len (group .classification ) > 0 {
733+ fmt .Fprintln (buf )
734+ }
735+ fmt .Fprintf (buf , group .classification )
730736 if len (group .suggestion ) > 0 {
737+ if len (group .classification ) > 0 {
738+ fmt .Fprintln (buf )
739+ }
731740 fmt .Fprintln (buf )
732741 }
733742 fmt .Fprint (buf , group .suggestion )
@@ -736,20 +745,22 @@ func handleError(err error, baseName, commandName, commandPath string, config *n
736745}
737746
738747type errorGroup struct {
739- errs []error
740- suggestion string
748+ errs []error
749+ suggestion string
750+ classification string
741751}
742752type errorGroups map [string ]errorGroup
743753
744- func (g errorGroups ) Add (group string , suggestion string , err error , errs ... error ) {
754+ func (g errorGroups ) Add (group string , suggestion string , classification string , err error , errs ... error ) {
745755 all := g [group ]
746756 all .errs = append (all .errs , errs ... )
747757 all .errs = append (all .errs , err )
748758 all .suggestion = suggestion
759+ all .classification = classification
749760 g [group ] = all
750761}
751762
752- func transformRunError (err error , baseName , commandName , commandPath string , groups errorGroups ) {
763+ func transformRunError (err error , baseName , commandName , commandPath string , groups errorGroups , config * newcmd. AppConfig ) {
753764 switch t := err .(type ) {
754765 case newcmd.ErrRequiresExplicitAccess :
755766 if t .Input .Token != nil && t .Input .Token .ServiceAccount {
@@ -762,6 +773,7 @@ func transformRunError(err error, baseName, commandName, commandPath string, gro
762773 You can see more information about the image by adding the --dry-run flag.
763774 If you trust the provided image, include the flag --grant-install-rights.` ,
764775 ),
776+ "" ,
765777 fmt .Errorf ("installing %q requires an 'installer' service account with project editor access" , t .Match .Value ),
766778 )
767779 } else {
@@ -774,11 +786,13 @@ func transformRunError(err error, baseName, commandName, commandPath string, gro
774786 You can see more information about the image by adding the --dry-run flag.
775787 If you trust the provided image, include the flag --grant-install-rights.` ,
776788 ),
789+ "" ,
777790 fmt .Errorf ("installing %q requires that you grant the image access to run with your credentials" , t .Match .Value ),
778791 )
779792 }
780793 return
781794 case newapp.ErrNoMatch :
795+ classification , _ := config .ComponentInputClassificationWinners [t .Value ]
782796 groups .Add (
783797 "no-matches" ,
784798 heredoc .Docf (`
@@ -794,11 +808,13 @@ func transformRunError(err error, baseName, commandName, commandPath string, gro
794808
795809 See '%[1]s -h' for examples.` , commandPath ,
796810 ),
811+ heredoc .Docf (classification ),
797812 t ,
798813 t .Errs ... ,
799814 )
800815 return
801816 case newapp.ErrMultipleMatches :
817+ classification , _ := config .ComponentInputClassificationWinners [t .Value ]
802818 buf := & bytes.Buffer {}
803819 for i , match := range t .Matches {
804820
@@ -812,6 +828,7 @@ func transformRunError(err error, baseName, commandName, commandPath string, gro
812828
813829 %[2]sTo view a full list of matches, use '%[3]s %[4]s -S %[1]s'` , t .Value , buf .String (), baseName , commandName ,
814830 ),
831+ classification ,
815832 t ,
816833 t .Errs ... ,
817834 )
@@ -830,11 +847,13 @@ func transformRunError(err error, baseName, commandName, commandPath string, gro
830847
831848 %[2]s` , t .Value , buf .String (),
832849 ),
850+ classification ,
833851 t ,
834852 t .Errs ... ,
835853 )
836854 return
837855 case newapp.ErrPartialMatch :
856+ classification , _ := config .ComponentInputClassificationWinners [t .Value ]
838857 buf := & bytes.Buffer {}
839858 fmt .Fprintf (buf , "* %s\n " , t .Match .Description )
840859 fmt .Fprintf (buf , " Use %[1]s to specify this image or template\n \n " , t .Match .Argument )
@@ -846,11 +865,13 @@ func transformRunError(err error, baseName, commandName, commandPath string, gro
846865
847866 %[2]s` , t .Value , buf .String (),
848867 ),
868+ classification ,
849869 t ,
850870 t .Errs ... ,
851871 )
852872 return
853873 case newapp.ErrNoTagsFound :
874+ classification , _ := config .ComponentInputClassificationWinners [t .Value ]
854875 buf := & bytes.Buffer {}
855876 fmt .Fprintf (buf , " Use --allow-missing-imagestream-tags to use this image stream\n \n " )
856877 groups .Add (
@@ -860,6 +881,7 @@ func transformRunError(err error, baseName, commandName, commandPath string, gro
860881
861882 %[2]s` , t .Match .Name , buf .String (),
862883 ),
884+ classification ,
863885 t ,
864886 t .Errs ... ,
865887 )
@@ -868,13 +890,14 @@ func transformRunError(err error, baseName, commandName, commandPath string, gro
868890 switch err {
869891 case errNoTokenAvailable :
870892 // TODO: improve by allowing token generation
871- groups .Add ("" , "" , fmt .Errorf ("to install components you must be logged in with an OAuth token (instead of only a certificate)" ))
893+ groups .Add ("" , "" , "" , fmt .Errorf ("to install components you must be logged in with an OAuth token (instead of only a certificate)" ))
872894 case newcmd .ErrNoInputs :
873895 // TODO: suggest things to the user
874- groups .Add ("" , "" , usageError (commandPath , newAppNoInput , baseName , commandName ))
896+ groups .Add ("" , "" , "" , usageError (commandPath , newAppNoInput , baseName , commandName ))
875897 default :
876- groups .Add ("" , "" , err )
898+ groups .Add ("" , "" , "" , err )
877899 }
900+ return
878901}
879902
880903func usageError (commandPath , format string , args ... interface {}) error {
0 commit comments