mirror of https://github.com/knative/func.git
Improve help for the `build` sub-command (#1023)
Signed-off-by: Matej Vasek <mvasek@redhat.com>
This commit is contained in:
parent
1d367c6be5
commit
8f405b691a
17
cmd/build.go
17
cmd/build.go
|
@ -39,22 +39,29 @@ and the image name is stored in the configuration file.
|
|||
# Re-build, picking up a previously supplied image name from a local func.yml
|
||||
{{.Name}} build
|
||||
|
||||
# Build using s2i instead of Buildpacks
|
||||
{{.Name}} build --builder=s2i
|
||||
|
||||
# Build with a custom buildpack builder
|
||||
{{.Name}} build --builder cnbs/sample-builder:bionic
|
||||
{{.Name}} build --builder=pack --builder-image cnbs/sample-builder:bionic
|
||||
`,
|
||||
SuggestFor: []string{"biuld", "buidl", "built"},
|
||||
PreRunE: bindEnv("image", "path", "builder", "registry", "confirm", "push", "builder-image"),
|
||||
}
|
||||
|
||||
cmd.Flags().StringP("builder", "b", "pack", "builder to use when creating the underlying image. Currently supported builders are 'pack' and 's2i'.")
|
||||
cmd.Flags().StringP("builder-image", "", "", "builder image, either an as a an image name or a mapping name.\nSpecified value is stored in func.yaml for subsequent builds. ($FUNC_BUILDER_IMAGE)")
|
||||
cmd.Flags().StringP("builder", "b", "pack", "build strategy to use when creating the underlying image. Currently supported build strategies are 'pack' and 's2i'.")
|
||||
cmd.Flags().StringP("builder-image", "", "", "builder image, either an as a an image name or a mapping name.\nSpecified value is stored in func.yaml (as 'builder' field) for subsequent builds. ($FUNC_BUILDER_IMAGE)")
|
||||
cmd.Flags().BoolP("confirm", "c", false, "Prompt to confirm all configuration options (Env: $FUNC_CONFIRM)")
|
||||
cmd.Flags().StringP("image", "i", "", "Full image name in the form [registry]/[namespace]/[name]:[tag] (optional). This option takes precedence over --registry (Env: $FUNC_IMAGE)")
|
||||
cmd.Flags().StringP("registry", "r", GetDefaultRegistry(), "Registry + namespace part of the image to build, ex 'quay.io/myuser'. The full image name is automatically determined based on the local directory name. If not provided the registry will be taken from func.yaml (Env: $FUNC_REGISTRY)")
|
||||
cmd.Flags().BoolP("push", "u", false, "Attempt to push the function image after being successfully built")
|
||||
setPathFlag(cmd)
|
||||
|
||||
if err := cmd.RegisterFlagCompletionFunc("builder", CompleteBuilderImageList); err != nil {
|
||||
if err := cmd.RegisterFlagCompletionFunc("builder", CompleteBuildStrategyList); err != nil {
|
||||
fmt.Println("internal: error while calling RegisterFlagCompletionFunc: ", err)
|
||||
}
|
||||
|
||||
if err := cmd.RegisterFlagCompletionFunc("builder-image", CompleteBuilderImageList); err != nil {
|
||||
fmt.Println("internal: error while calling RegisterFlagCompletionFunc: ", err)
|
||||
}
|
||||
|
||||
|
@ -155,7 +162,7 @@ func runBuild(cmd *cobra.Command, _ []string, newClient ClientFactory) (err erro
|
|||
} else if config.Builder == "s2i" {
|
||||
builder = s2i.NewBuilder(config.Verbose)
|
||||
} else {
|
||||
err = errors.New("unrecognized builder")
|
||||
err = errors.New("unrecognized builder: valid values are: s2i, pack")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ func CompleteRegistryList(cmd *cobra.Command, args []string, toComplete string)
|
|||
return
|
||||
}
|
||||
|
||||
func CompleteBuilderImageList(cmd *cobra.Command, args []string, complete string) (strings []string, directive cobra.ShellCompDirective) {
|
||||
func CompleteBuilderImageList(cmd *cobra.Command, args []string, complete string) (builderImages []string, directive cobra.ShellCompDirective) {
|
||||
directive = cobra.ShellCompDirectiveError
|
||||
|
||||
var (
|
||||
|
@ -114,12 +114,18 @@ func CompleteBuilderImageList(cmd *cobra.Command, args []string, complete string
|
|||
return
|
||||
}
|
||||
|
||||
strings = make([]string, 0, len(f.Builders))
|
||||
builderImages = make([]string, 0, len(f.Builders))
|
||||
for name := range f.Builders {
|
||||
strings = append(strings, name)
|
||||
if len(complete) == 0 {
|
||||
builderImages = append(builderImages, name)
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(name, complete) {
|
||||
builderImages = append(builderImages, name)
|
||||
}
|
||||
}
|
||||
|
||||
directive = cobra.ShellCompDirectiveDefault
|
||||
directive = cobra.ShellCompDirectiveNoFileComp
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -128,3 +134,15 @@ func CompleteDeployBuildType(cmd *cobra.Command, args []string, complete string)
|
|||
directive = cobra.ShellCompDirectiveDefault
|
||||
return
|
||||
}
|
||||
|
||||
func CompleteBuildStrategyList(cmd *cobra.Command, args []string, complete string) ([]string, cobra.ShellCompDirective) {
|
||||
if len(complete) >= 1 {
|
||||
if strings.HasPrefix("pack", complete) {
|
||||
return []string{"pack"}, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
if strings.HasPrefix("s2i", complete) {
|
||||
return []string{"s2i"}, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
}
|
||||
return []string{"pack", "s2i"}, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue