@@ -605,7 +605,29 @@ 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 := range unknown {
611+ fmt .Fprintf (buf , "%s:\n " , argName )
612+ for _ , classErr := range config .EnvironmentClassificationErrors {
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+ for _ , classErr := range config .SourceClassificationErrors {
620+ fmt .Fprintf (buf , fmt .Sprintf ("%s: %v\n " , classErr .Key , classErr .Value ))
621+ }
622+ for _ , classErr := range config .TemplateClassificationErrors {
623+ fmt .Fprintf (buf , fmt .Sprintf ("%s: %v\n " , classErr .Key , classErr .Value ))
624+ }
625+ for _ , classErr := range config .ComponentClassificationErrors {
626+ fmt .Fprintf (buf , fmt .Sprintf ("%s: %v\n " , classErr .Key , classErr .Value ))
627+ }
628+ fmt .Fprintln (buf )
629+ }
630+ return kcmdutil .UsageErrorf (c , heredoc .Docf (buf .String ()))
609631 }
610632
611633 if config .AllowMissingImages && config .AsSearch {
@@ -701,7 +723,7 @@ func retryBuildConfig(info *resource.Info, err error) runtime.Object {
701723 return nil
702724}
703725
704- func handleError (err error , baseName , commandName , commandPath string , config * newcmd.AppConfig , transformError func (err error , baseName , commandName , commandPath string , groups errorGroups )) error {
726+ 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 {
705727 if err == nil {
706728 return nil
707729 }
@@ -711,23 +733,19 @@ func handleError(err error, baseName, commandName, commandPath string, config *n
711733 }
712734 groups := errorGroups {}
713735 for _ , err := range errs {
714- transformError (err , baseName , commandName , commandPath , groups )
736+ transformError (err , baseName , commandName , commandPath , groups , config )
715737 }
716738 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- }
728739 for _ , group := range groups {
729740 fmt .Fprint (buf , kcmdutil .MultipleErrors ("error: " , group .errs ))
741+ if len (group .classification ) > 0 {
742+ fmt .Fprintln (buf )
743+ }
744+ fmt .Fprintf (buf , group .classification )
730745 if len (group .suggestion ) > 0 {
746+ if len (group .classification ) > 0 {
747+ fmt .Fprintln (buf )
748+ }
731749 fmt .Fprintln (buf )
732750 }
733751 fmt .Fprint (buf , group .suggestion )
@@ -736,20 +754,22 @@ func handleError(err error, baseName, commandName, commandPath string, config *n
736754}
737755
738756type errorGroup struct {
739- errs []error
740- suggestion string
757+ errs []error
758+ suggestion string
759+ classification string
741760}
742761type errorGroups map [string ]errorGroup
743762
744- func (g errorGroups ) Add (group string , suggestion string , err error , errs ... error ) {
763+ func (g errorGroups ) Add (group string , suggestion string , classification string , err error , errs ... error ) {
745764 all := g [group ]
746765 all .errs = append (all .errs , errs ... )
747766 all .errs = append (all .errs , err )
748767 all .suggestion = suggestion
768+ all .classification = classification
749769 g [group ] = all
750770}
751771
752- func transformRunError (err error , baseName , commandName , commandPath string , groups errorGroups ) {
772+ func transformRunError (err error , baseName , commandName , commandPath string , groups errorGroups , config * newcmd. AppConfig ) {
753773 switch t := err .(type ) {
754774 case newcmd.ErrRequiresExplicitAccess :
755775 if t .Input .Token != nil && t .Input .Token .ServiceAccount {
@@ -762,6 +782,7 @@ func transformRunError(err error, baseName, commandName, commandPath string, gro
762782 You can see more information about the image by adding the --dry-run flag.
763783 If you trust the provided image, include the flag --grant-install-rights.` ,
764784 ),
785+ "" ,
765786 fmt .Errorf ("installing %q requires an 'installer' service account with project editor access" , t .Match .Value ),
766787 )
767788 } else {
@@ -774,11 +795,19 @@ func transformRunError(err error, baseName, commandName, commandPath string, gro
774795 You can see more information about the image by adding the --dry-run flag.
775796 If you trust the provided image, include the flag --grant-install-rights.` ,
776797 ),
798+ "" ,
777799 fmt .Errorf ("installing %q requires that you grant the image access to run with your credentials" , t .Match .Value ),
778800 )
779801 }
780802 return
781803 case newapp.ErrNoMatch :
804+ classification , _ := config .ClassificationWinners [t .Value ]
805+ if classification .IncludeGitErrors {
806+ notGitRepo , ok := config .SourceClassificationErrors [t .Value ]
807+ if ok {
808+ t .Errs = append (t .Errs , notGitRepo .Value )
809+ }
810+ }
782811 groups .Add (
783812 "no-matches" ,
784813 heredoc .Docf (`
@@ -794,11 +823,13 @@ func transformRunError(err error, baseName, commandName, commandPath string, gro
794823
795824 See '%[1]s -h' for examples.` , commandPath ,
796825 ),
826+ heredoc .Docf (classification .String ()),
797827 t ,
798828 t .Errs ... ,
799829 )
800830 return
801831 case newapp.ErrMultipleMatches :
832+ classification , _ := config .ClassificationWinners [t .Value ]
802833 buf := & bytes.Buffer {}
803834 for i , match := range t .Matches {
804835
@@ -812,6 +843,7 @@ func transformRunError(err error, baseName, commandName, commandPath string, gro
812843
813844 %[2]sTo view a full list of matches, use '%[3]s %[4]s -S %[1]s'` , t .Value , buf .String (), baseName , commandName ,
814845 ),
846+ classification .String (),
815847 t ,
816848 t .Errs ... ,
817849 )
@@ -830,11 +862,13 @@ func transformRunError(err error, baseName, commandName, commandPath string, gro
830862
831863 %[2]s` , t .Value , buf .String (),
832864 ),
865+ classification .String (),
833866 t ,
834867 t .Errs ... ,
835868 )
836869 return
837870 case newapp.ErrPartialMatch :
871+ classification , _ := config .ClassificationWinners [t .Value ]
838872 buf := & bytes.Buffer {}
839873 fmt .Fprintf (buf , "* %s\n " , t .Match .Description )
840874 fmt .Fprintf (buf , " Use %[1]s to specify this image or template\n \n " , t .Match .Argument )
@@ -846,11 +880,13 @@ func transformRunError(err error, baseName, commandName, commandPath string, gro
846880
847881 %[2]s` , t .Value , buf .String (),
848882 ),
883+ classification .String (),
849884 t ,
850885 t .Errs ... ,
851886 )
852887 return
853888 case newapp.ErrNoTagsFound :
889+ classification , _ := config .ClassificationWinners [t .Value ]
854890 buf := & bytes.Buffer {}
855891 fmt .Fprintf (buf , " Use --allow-missing-imagestream-tags to use this image stream\n \n " )
856892 groups .Add (
@@ -860,6 +896,7 @@ func transformRunError(err error, baseName, commandName, commandPath string, gro
860896
861897 %[2]s` , t .Match .Name , buf .String (),
862898 ),
899+ classification .String (),
863900 t ,
864901 t .Errs ... ,
865902 )
@@ -868,13 +905,14 @@ func transformRunError(err error, baseName, commandName, commandPath string, gro
868905 switch err {
869906 case errNoTokenAvailable :
870907 // 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)" ))
908+ groups .Add ("" , "" , "" , fmt .Errorf ("to install components you must be logged in with an OAuth token (instead of only a certificate)" ))
872909 case newcmd .ErrNoInputs :
873910 // TODO: suggest things to the user
874- groups .Add ("" , "" , usageError (commandPath , newAppNoInput , baseName , commandName ))
911+ groups .Add ("" , "" , "" , usageError (commandPath , newAppNoInput , baseName , commandName ))
875912 default :
876- groups .Add ("" , "" , err )
913+ groups .Add ("" , "" , "" , err )
877914 }
915+ return
878916}
879917
880918func usageError (commandPath , format string , args ... interface {}) error {
0 commit comments