@@ -118,6 +118,13 @@ type AppConfig struct {
118118
119119 OSClient client.Interface
120120 OriginNamespace string
121+
122+ ArgumentClassificationErrors []ArgumentClassificationError
123+ }
124+
125+ type ArgumentClassificationError struct {
126+ Key string
127+ Value error
121128}
122129
123130type ErrRequiresExplicitAccess struct {
@@ -220,30 +227,92 @@ func (c *AppConfig) SetOpenShiftClient(osclient client.Interface, OriginNamespac
220227 }
221228}
222229
230+ func (c * AppConfig ) tryToAddEnvironmentArguments (s string ) bool {
231+ rc := cmdutil .IsEnvironmentArgument (s )
232+ if rc {
233+ glog .V (2 ).Infof ("treating %s as possible environment argument\n " , s )
234+ c .Environment = append (c .Environment , s )
235+ }
236+ return rc
237+ }
238+
239+ func (c * AppConfig ) tryToAddSourceArguments (s string ) bool {
240+ remote , rerr := app .IsRemoteRepository (s )
241+ local , derr := app .IsDirectory (s )
242+
243+ if remote || local {
244+ glog .V (2 ).Infof ("treating %s as possible source repo\n " , s )
245+ c .SourceRepositories = append (c .SourceRepositories , s )
246+ return true
247+ }
248+
249+ if rerr != nil {
250+ c .ArgumentClassificationErrors = append (c .ArgumentClassificationErrors , ArgumentClassificationError {
251+ Key : fmt .Sprintf ("%s as a Git repository URL" , s ),
252+ Value : rerr ,
253+ })
254+ }
255+
256+ if derr != nil {
257+ c .ArgumentClassificationErrors = append (c .ArgumentClassificationErrors , ArgumentClassificationError {
258+ Key : fmt .Sprintf ("%s as a local directory pointing to a Git repository" , s ),
259+ Value : derr ,
260+ })
261+ }
262+
263+ return false
264+ }
265+
266+ func (c * AppConfig ) tryToAddComponentArguments (s string ) bool {
267+ err := app .IsComponentReference (s )
268+ if err == nil {
269+ glog .V (2 ).Infof ("treating %s as a component ref\n " , s )
270+ c .Components = append (c .Components , s )
271+ return true
272+ }
273+ c .ArgumentClassificationErrors = append (c .ArgumentClassificationErrors , ArgumentClassificationError {
274+ Key : fmt .Sprintf ("%s as a template loaded in an accessible project, an imagestream tag, or a docker image reference" , s ),
275+ Value : err ,
276+ })
277+
278+ return false
279+ }
280+
281+ func (c * AppConfig ) tryToAddTemplateArguments (s string ) bool {
282+ rc , err := app .IsPossibleTemplateFile (s )
283+ if rc {
284+ glog .V (2 ).Infof ("treating %s as possible template file\n " , s )
285+ c .Components = append (c .Components , s )
286+ return true
287+ }
288+ if err != nil {
289+ c .ArgumentClassificationErrors = append (c .ArgumentClassificationErrors , ArgumentClassificationError {
290+ Key : fmt .Sprintf ("%s as a template stored in a local file" , s ),
291+ Value : err ,
292+ })
293+ }
294+ return false
295+ }
296+
223297// AddArguments converts command line arguments into the appropriate bucket based on what they look like
224298func (c * AppConfig ) AddArguments (args []string ) []string {
225299 unknown := []string {}
300+ c .ArgumentClassificationErrors = []ArgumentClassificationError {}
226301 for _ , s := range args {
302+ if len (s ) == 0 {
303+ continue
304+ }
305+
227306 switch {
228- case cmdutil .IsEnvironmentArgument (s ):
229- glog .V (2 ).Infof ("treating %s as possible environment argument\n " , s )
230- c .Environment = append (c .Environment , s )
231- case app .IsPossibleSourceRepository (s ):
232- glog .V (2 ).Infof ("treating %s as possible source repo\n " , s )
233- c .SourceRepositories = append (c .SourceRepositories , s )
234- case app .IsComponentReference (s ):
235- glog .V (2 ).Infof ("treating %s as a component ref\n " , s )
236- c .Components = append (c .Components , s )
237- case app .IsPossibleTemplateFile (s ):
238- glog .V (2 ).Infof ("treating %s as possible template file\n " , s )
239- c .Components = append (c .Components , s )
307+ case c .tryToAddEnvironmentArguments (s ):
308+ case c .tryToAddSourceArguments (s ):
309+ case c .tryToAddComponentArguments (s ):
310+ case c .tryToAddTemplateArguments (s ):
240311 default :
241312 glog .V (2 ).Infof ("treating %s as unknown\n " , s )
242- if len (s ) == 0 {
243- break
244- }
245313 unknown = append (unknown , s )
246314 }
315+
247316 }
248317 return unknown
249318}
@@ -644,7 +713,7 @@ func (c *AppConfig) Run() (*AppResult, error) {
644713 // TODO: I don't belong here
645714 c .ensureDockerSearch ()
646715
647- resolved , err := Resolve (& c . Resolvers , & c . ComponentInputs , & c . GenerationInputs )
716+ resolved , err := Resolve (c )
648717 if err != nil {
649718 return nil , err
650719 }
0 commit comments