feat: completion --build flag of deploy sub-cmd (#802)

* feat: completion --build flag of deploy sub-cmd

Signed-off-by: Matej Vasek <mvasek@redhat.com>

* src: refactor

Moved functionality.

Signed-off-by: Matej Vasek <mvasek@redhat.com>
This commit is contained in:
Matej Vasek 2022-02-01 15:58:31 +01:00 committed by GitHub
parent 6c6ea0dadc
commit fff00497f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 0 deletions

View File

@ -125,3 +125,9 @@ func CompleteBuilderList(cmd *cobra.Command, args []string, complete string) (st
directive = cobra.ShellCompDirectiveDefault
return
}
func CompleteDeployBuildType(cmd *cobra.Command, args []string, complete string) (buildTypes []string, directive cobra.ShellCompDirective) {
buildTypes = fn.AllBuildTypes()
directive = cobra.ShellCompDirectiveDefault
return
}

View File

@ -124,6 +124,10 @@ kn func deploy --image quay.io/myuser/myfunc -n myns
setPathFlag(cmd)
setNamespaceFlag(cmd)
if err := cmd.RegisterFlagCompletionFunc("build", CompleteDeployBuildType); err != nil {
fmt.Println("internal: error while calling RegisterFlagCompletionFunc: ", err)
}
cmd.RunE = func(cmd *cobra.Command, args []string) error {
return runDeploy(cmd, args, clientFn)
}

View File

@ -11,6 +11,10 @@ const (
//BuildTypeRemote = "remote" // TODO not supported yet
)
func AllBuildTypes() []string {
return []string{BuildTypeLocal, BuildTypeGit, BuildTypeDisabled}
}
// ValidateBuild validates input Build type option from Function config.
// If "allowUnset" is set to true, the specified type could be "" -> fallback to DefaultBuildType,
// this option should be used for validating func.yaml file, where users don't have to specify the build type.