Skip to content

Commit 5dd72d7

Browse files
authored
chore: Update help messages and adding examples. (#218)
* chore: Update help messages and adding examples. This commit introduces fixes for the top-level help message as described in #187. It does not address: * #216 - Use `kn function` in help message when run as a plugin to kn * #215 - Group main help message to put important commands to the top * #214 - Make examples in usage message parameterizable
1 parent b595500 commit 5dd72d7

File tree

10 files changed

+165
-125
lines changed

10 files changed

+165
-125
lines changed

Diff for: cmd/build.go

+34-27
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,43 @@ import (
1313

1414
func init() {
1515
root.AddCommand(buildCmd)
16-
buildCmd.Flags().StringP("builder", "b", "default", "Buildpacks builder")
17-
buildCmd.Flags().BoolP("confirm", "c", false, "Prompt to confirm all configuration options - $FUNC_CONFIRM")
18-
buildCmd.Flags().StringP("image", "i", "", "Optional full image name, in form [registry]/[namespace]/[name]:[tag] for example quay.io/myrepo/project.name:latest (overrides --registry) - $FUNC_IMAGE")
19-
buildCmd.Flags().StringP("path", "p", cwd(), "Path to the Function project directory - $FUNC_PATH")
20-
buildCmd.Flags().StringP("registry", "r", "", "Registry for built images, ex 'docker.io/myuser' or just 'myuser'. Optional if --image provided. - $FUNC_REGISTRY")
16+
buildCmd.Flags().StringP("builder", "b", "default", "Buildpack builder, either an as a an image name or a mapping name as defined in func.yaml")
17+
buildCmd.Flags().BoolP("confirm", "c", false, "Prompt to confirm all configuration options (Env: $FUNC_CONFIRM)")
18+
buildCmd.Flags().StringP("image", "i", "", "Full image name in the orm [registry]/[namespace]/[name]:[tag] (optional). This option takes precedence over --registry (Env: $FUNC_IMAGE")
19+
buildCmd.Flags().StringP("path", "p", cwd(), "Path to the project directory (Env: $FUNC_PATH)")
20+
buildCmd.Flags().StringP("registry", "r", "", "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)")
2121

2222
err := buildCmd.RegisterFlagCompletionFunc("builder", CompleteBuilderList)
2323
if err != nil {
24-
fmt.Println("Error while calling RegisterFlagCompletionFunc: ", err)
24+
fmt.Println("internal: error while calling RegisterFlagCompletionFunc: ", err)
2525
}
2626
}
2727

2828
var buildCmd = &cobra.Command{
2929
Use: "build",
30-
Short: "Build an existing Function project as an OCI image",
31-
Long: `Build an existing Function project as an OCI image
32-
33-
Builds the Function project in the current directory or in the directory
34-
specified by the --path flag. The func.yaml file is read to determine the
35-
image name and registry. If both of these values are unset in the
36-
configuration file the --registry or -r flag should be provided and an image
37-
name will be derived from the project name.
38-
39-
Any value provided for the --image flag will be persisted in the func.yaml
40-
configuration file. On subsequent invocations of the "build" command
41-
these values will be read from the configuration file.
42-
43-
It's possible to use a custom Buildpack builder with the --builder flag.
44-
The value may be image name e.g. "cnbs/sample-builder:bionic",
45-
or reference to builderMaps in the config file e.g. "default".
30+
Short: "Build a function project as a container image",
31+
Long: `Build a function project as a container image
32+
33+
This command builds the function project in the current directory or in the directory
34+
specified by --path. The result will be a container image that is pushed to a registry.
35+
The func.yaml file is read to determine the image name and registry.
36+
If the project has not already been built, either --registry or --image must be provided
37+
and the image name is stored in the configuration file.
38+
`,
39+
Example: `
40+
# Build from the local directory, using the given registry as target.
41+
# The full image name will be determined automatically based on the
42+
# project directory name
43+
kn func build --registry quay.io/myuser
44+
45+
# Build from the local directory, specifying the full image name
46+
kn func build --image quay.io/myuser/myfunc
47+
48+
# Re-build, picking up a previously supplied image name from a local func.yml
49+
kn func build
50+
51+
# Build with a custom buildpack builder
52+
kn func build --builder cnbs/sample-builder:bionic
4653
`,
4754
SuggestFor: []string{"biuld", "buidl", "built"},
4855
PreRunE: bindEnv("image", "path", "builder", "registry", "confirm"),
@@ -59,18 +66,18 @@ func runBuild(cmd *cobra.Command, _ []string) (err error) {
5966

6067
// Check if the Function has been initialized
6168
if !function.Initialized() {
62-
return fmt.Errorf("the given path '%v' does not contain an initialized Function. Please create one at this path before deploying.", config.Path)
69+
return fmt.Errorf("the given path '%v' does not contain an initialized function. Please create one at this path before deploying", config.Path)
6370
}
6471

6572
// If the Function does not yet have an image name and one was not provided on the command line
6673
if function.Image == "" {
6774
// AND a --registry was not provided, then we need to
6875
// prompt for a registry from which we can derive an image name.
6976
if config.Registry == "" {
70-
fmt.Print("A registry for Function images is required. For example, 'docker.io/tigerteam'.\n\n")
71-
config.Registry = prompt.ForString("Registry for Function images", "")
77+
fmt.Print("A registry for function images is required (e.g. 'quay.io/boson').\n\n")
78+
config.Registry = prompt.ForString("Registry for function images", "")
7279
if config.Registry == "" {
73-
return fmt.Errorf("Unable to determine Function image name")
80+
return fmt.Errorf("unable to determine function image name")
7481
}
7582
}
7683

@@ -142,7 +149,7 @@ func (c buildConfig) Prompt() buildConfig {
142149
}
143150
return buildConfig{
144151
Path: prompt.ForString("Path to project directory", c.Path),
145-
Image: prompt.ForString("Image name", imageName, prompt.WithRequired(true)),
152+
Image: prompt.ForString("Full image name (e.g. quay.io/boson/node-sample)", imageName, prompt.WithRequired(true)),
146153
Verbose: c.Verbose,
147154
// Registry not prompted for as it would be confusing when combined with explicit image. Instead it is
148155
// inferred by the derived default for Image, which uses Registry for derivation.

Diff for: cmd/completion.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func init() {
1414
// completionCmd represents the completion command
1515
var completionCmd = &cobra.Command{
1616
Use: "completion <bash|zsh|fish>",
17-
Short: "Generate bash/zsh completion scripts",
17+
Short: "Generate completion scripts for bash, fish and zsh",
1818
Long: `To load completion run
1919
2020
For zsh:

Diff for: cmd/create.go

+23-18
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,36 @@ import (
1313

1414
func init() {
1515
root.AddCommand(createCmd)
16-
createCmd.Flags().BoolP("confirm", "c", false, "Prompt to confirm all configuration options - $FUNC_CONFIRM")
17-
createCmd.Flags().StringP("runtime", "l", faas.DefaultRuntime, "Function runtime language/framework. Default runtime is 'node'. Available runtimes: 'node', 'quarkus' and 'go'. - $FUNC_RUNTIME")
18-
createCmd.Flags().StringP("templates", "", filepath.Join(configPath(), "templates"), "Extensible templates path. - $FUNC_TEMPLATES")
19-
createCmd.Flags().StringP("trigger", "t", faas.DefaultTrigger, "Function trigger. Default trigger is 'http'. Available triggers: 'http' and 'events' - $FUNC_TRIGGER")
16+
createCmd.Flags().BoolP("confirm", "c", false, "Prompt to confirm all configuration options (Env: $FUNC_CONFIRM)")
17+
createCmd.Flags().StringP("runtime", "l", faas.DefaultRuntime, "Function runtime language/framework. Available runtimes: 'node', 'quarkus' and 'go' (Env: $FUNC_RUNTIME)")
18+
createCmd.Flags().StringP("templates", "", filepath.Join(configPath(), "templates"), "Path to additional templates (Env: $FUNC_TEMPLATES)")
19+
createCmd.Flags().StringP("trigger", "t", faas.DefaultTrigger, "Function trigger. Available triggers: 'http' and 'events' (Env: $FUNC_TRIGGER)")
2020

2121
if err := createCmd.RegisterFlagCompletionFunc("runtime", CompleteRuntimeList); err != nil {
22-
fmt.Println("Error while calling RegisterFlagCompletionFunc: ", err)
22+
fmt.Println("internal: error while calling RegisterFlagCompletionFunc: ", err)
2323
}
2424
}
2525

2626
var createCmd = &cobra.Command{
27-
Use: "create <path>",
28-
Short: "Create a new Function project",
29-
Long: `Create a new Function project
27+
Use: "create [PATH]",
28+
Short: "Create a function project",
29+
Long: `Create a function project
3030
31-
Creates a new Function project at <path>. If <path> does not exist, it is
32-
created. The Function name is the name of the leaf directory at <path>.
33-
34-
A project for a Node.js Function will be created by default. Specify an
35-
alternate runtime with the --language or -l flag. Available alternates are
36-
"quarkus" and "go".
37-
38-
Use the --trigger or -t flag to specify the function invocation context.
39-
By default, the trigger is "http". To create a Function for CloudEvents, use
40-
"events".
31+
Creates a new function project in PATH, or in the current directory if no PATH is given.
32+
The name of the project is determined by the directory name the project is created in.
33+
`,
34+
Example: `
35+
# Create a Node.js function project in the current directory, choosing the
36+
# directory name as the project's name.
37+
kn func create
38+
39+
# Create a Quarkus function project in the directory "sample-service".
40+
# The directory will be created in the local directory if non-existent and
41+
# the project is called "sample-service"
42+
kn func create --runtime quarkus myfunc
43+
44+
# Create a function project that uses a CloudEvent based function signature
45+
kn func create --trigger events myfunc
4146
`,
4247
SuggestFor: []string{"inti", "new"},
4348
PreRunE: bindEnv("runtime", "templates", "trigger", "confirm"),

Diff for: cmd/delete.go

+20-17
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,28 @@ import (
1313

1414
func init() {
1515
root.AddCommand(deleteCmd)
16-
deleteCmd.Flags().BoolP("confirm", "c", false, "Prompt to confirm all configuration options - $FUNC_CONFIRM")
17-
deleteCmd.Flags().StringP("path", "p", cwd(), "Path to the project which should be deleted - $FUNC_PATH")
18-
deleteCmd.Flags().StringP("namespace", "n", "", "Override namespace in which to search for Functions. Default is to use currently active underlying platform setting - $FAAS_NAMESPACE")
16+
deleteCmd.Flags().BoolP("confirm", "c", false, "Prompt to confirm all configuration options (Env: $FUNC_CONFIRM)")
17+
deleteCmd.Flags().StringP("path", "p", cwd(), "Path to the function project that should be undeployed (Env: $FUNC_PATH)")
18+
deleteCmd.Flags().StringP("namespace", "n", "", "Namespace of the function to undeploy. By default, the namespace in func.yaml is used or the actual active namespace if not set in the configuration. (Env: $FUNC_NAMESPACE)")
1919
}
2020

2121
var deleteCmd = &cobra.Command{
22-
Use: "delete <name>",
23-
Short: "Delete a Function deployment",
24-
Long: `Delete a Function deployment
25-
26-
Removes a deployed function from the cluster. The user may specify a function
27-
by name, path using the --path or -p flag, or if neither of those are provided,
28-
the current directory will be searched for a func.yaml configuration file to
29-
determine the function to be removed.
30-
31-
The namespace defaults to the value in func.yaml or the namespace currently
32-
active in the user's Kubernetes configuration. The namespace may be specified
33-
on the command line using the --namespace or -n flag, and if so this will
34-
overwrite the value in func.yaml.
22+
Use: "delete [NAME]",
23+
Short: "Undeploy a function",
24+
Long: `Undeploy a function
25+
26+
This command undeploys a function from the cluster. By default the function from
27+
the project in the current directory is undeployed. Alternatively either the name
28+
of the function can be given as argument or the project path provided with --path.
29+
30+
No local files are deleted.
31+
`,
32+
Example: `
33+
# Undeploy the function defined in the local directory
34+
kn func delete
35+
36+
# Undeploy the function 'myfunc' in namespace 'apps'
37+
kn func delete -n apps myfunc
3538
`,
3639
SuggestFor: []string{"remove", "rm", "del"},
3740
ValidArgsFunction: CompleteFunctionList,
@@ -49,7 +52,7 @@ func runDelete(cmd *cobra.Command, args []string) (err error) {
4952

5053
// Check if the Function has been initialized
5154
if !function.Initialized() {
52-
return fmt.Errorf("the given path '%v' does not contain an initialized Function.", config.Path)
55+
return fmt.Errorf("the given path '%v' does not contain an initialized function", config.Path)
5356
}
5457

5558
ns := config.Namespace

Diff for: cmd/deploy.go

+28-26
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,39 @@ import (
1515

1616
func init() {
1717
root.AddCommand(deployCmd)
18-
deployCmd.Flags().BoolP("confirm", "c", false, "Prompt to confirm all configuration options - $FUNC_CONFIRM")
19-
deployCmd.Flags().StringArrayP("env", "e", []string{}, "Sets environment variables for the Function.")
20-
deployCmd.Flags().StringP("image", "i", "", "Optional full image name, in form [registry]/[namespace]/[name]:[tag] for example quay.io/myrepo/project.name:latest (overrides --registry) - $FUNC_IMAGE")
21-
deployCmd.Flags().StringP("namespace", "n", "", "Override namespace into which the Function is deployed (on supported platforms). Default is to use currently active underlying platform setting - $FUNC_NAMESPACE")
22-
deployCmd.Flags().StringP("path", "p", cwd(), "Path to the function project directory - $FUNC_PATH")
23-
deployCmd.Flags().StringP("registry", "r", "", "Image registry for built images, ex 'docker.io/myuser' or just 'myuser'. - $FUNC_REGISTRY")
18+
deployCmd.Flags().BoolP("confirm", "c", false, "Prompt to confirm all configuration options (Env: $FUNC_CONFIRM)")
19+
deployCmd.Flags().StringArrayP("env", "e", []string{}, "Environment variable to set in the form NAME=VALUE. You may provide this flag multiple times for setting multiple environment variables.")
20+
deployCmd.Flags().StringP("image", "i", "", "Full image name in the orm [registry]/[namespace]/[name]:[tag] (optional). This option takes precedence over --registry (Env: $FUNC_IMAGE")
21+
deployCmd.Flags().StringP("namespace", "n", "", "Namespace of the function to undeploy. By default, the namespace in func.yaml is used or the actual active namespace if not set in the configuration. (Env: $FUNC_NAMESPACE)")
22+
deployCmd.Flags().StringP("path", "p", cwd(), "Path to the project directory (Env: $FUNC_PATH)")
23+
deployCmd.Flags().StringP("registry", "r", "", "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)")
2424
}
2525

2626
var deployCmd = &cobra.Command{
2727
Use: "deploy",
28-
Short: "Deploy an existing Function project to a cluster",
29-
Long: `Deploy an existing Function project to a cluster
30-
31-
Builds and Deploys the Function project in the current directory.
32-
A path to the project directory may be provided using the --path or -p flag.
33-
Reads the func.yaml configuration file to determine the image name.
34-
An image and registry may be specified on the command line using
35-
the --image or -i and --registry or -r flag.
36-
37-
If the Function is already deployed, it is updated with a new container image
38-
that is pushed to an image registry, and the Knative Service is updated.
39-
40-
The namespace into which the project is deployed defaults to the value in the
41-
func.yaml configuration file. If NAMESPACE is not set in the configuration,
42-
the namespace currently active in the Kubernetes configuration file will be
43-
used. The namespace may be specified on the command line using the --namespace
44-
or -n flag, and if so this will overwrite the value in the func.yaml file.
28+
Short: "Deploy a function",
29+
Long: `Deploy a function
4530
31+
Builds a container image for the function and deploys it to the connected Knative enabled cluster.
32+
The function is picked up from the project in the current directory or from the path provided
33+
with --path.
34+
If not already configured, either --registry or --image has to be provided and is then stored
35+
in the configuration file.
4636
37+
If the function is already deployed, it is updated with a new container image
38+
that is pushed to an image registry, and finally the function's Knative service is updated.
39+
`,
40+
Example: `
41+
# Build and deploy the function from the current directory's project. The image will be
42+
# pushed to "quay.io/myuser/<function name>" and deployed as Knative service with the
43+
# same name as the function to the currently connected cluster.
44+
kn func deploy --registry quay.io/myuser
45+
46+
# Same as above but using a full image name, that will create a Knative service "myfunc" in
47+
# the namespace "myns"
48+
kn func deploy --image quay.io/myuser/myfunc -n myns
4749
`,
48-
SuggestFor: []string{"delpoy", "deplyo"},
50+
SuggestFor: []string{"delpoy", "deplyo"},
4951
PreRunE: bindEnv("image", "namespace", "path", "registry", "confirm"),
5052
RunE: runDeploy,
5153
}
@@ -63,7 +65,7 @@ func runDeploy(cmd *cobra.Command, _ []string) (err error) {
6365

6466
// Check if the Function has been initialized
6567
if !function.Initialized() {
66-
return fmt.Errorf("the given path '%v' does not contain an initialized Function. Please create one at this path before deploying.", config.Path)
68+
return fmt.Errorf("the given path '%v' does not contain an initialized function. Please create one at this path before deploying", config.Path)
6769
}
6870

6971
// If the Function does not yet have an image name and one was not provided on the command line
@@ -74,7 +76,7 @@ func runDeploy(cmd *cobra.Command, _ []string) (err error) {
7476
fmt.Print("A registry for Function images is required. For example, 'docker.io/tigerteam'.\n\n")
7577
config.Registry = prompt.ForString("Registry for Function images", "")
7678
if config.Registry == "" {
77-
return fmt.Errorf("Unable to determine Function image name")
79+
return fmt.Errorf("unable to determine function image name")
7880
}
7981
}
8082

Diff for: cmd/describe.go

+15-13
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,30 @@ import (
1717

1818
func init() {
1919
root.AddCommand(describeCmd)
20-
describeCmd.Flags().StringP("namespace", "n", "", "Override namespace in which to search for the Function. Default is to use currently active underlying platform setting - $FUNC_NAMESPACE")
21-
describeCmd.Flags().StringP("format", "f", "human", "optionally specify output format (human|plain|json|xml|yaml) $FUNC_FORMAT")
22-
describeCmd.Flags().StringP("path", "p", cwd(), "Path to the project which should be described - $FUNC_PATH")
20+
describeCmd.Flags().StringP("namespace", "n", "", "Namespace of the function to undeploy. By default, the namespace in func.yaml is used or the actual active namespace if not set in the configuration. (Env: $FUNC_NAMESPACE)")
21+
describeCmd.Flags().StringP("format", "f", "human", "Output format (human|plain|json|xml|yaml) (Env: $FUNC_FORMAT)")
22+
describeCmd.Flags().StringP("path", "p", cwd(), "Path to the project directory (Env: $FUNC_PATH)")
2323

2424
err := describeCmd.RegisterFlagCompletionFunc("format", CompleteOutputFormatList)
2525
if err != nil {
26-
fmt.Println("Error while calling RegisterFlagCompletionFunc: ", err)
26+
fmt.Println("internal: error while calling RegisterFlagCompletionFunc: ", err)
2727
}
2828
}
2929

3030
var describeCmd = &cobra.Command{
3131
Use: "describe <name>",
32-
Short: "Describes the Function",
33-
Long: `Describes the Function
32+
Short: "Show details of a function",
33+
Long: `Show details of a function
3434
35-
Prints the name, route and any event subscriptions for a deployed Function in
36-
the current directory. A path to a Function project directory may be supplied
37-
using the --path or -p flag.
35+
Prints the name, route and any event subscriptions for a deployed function in
36+
the current directory or from the directory specified with --path.
37+
`,
38+
Example: `
39+
# Show the details of a function as declared in the local func.yaml
40+
kn func describe
3841
39-
The namespace defaults to the value in func.yaml or the namespace currently
40-
active in the user's Kubernetes configuration. The namespace may be specified
41-
using the --namespace or -n flag, and if so this will overwrite the value in func.yaml.
42+
# Show the details of the function in YAML format for the function in the myotherfunc directory
43+
kn func describe --format yaml --path myotherfunc
4244
`,
4345
SuggestFor: []string{"desc", "get"},
4446
ValidArgsFunction: CompleteFunctionList,
@@ -56,7 +58,7 @@ func runDescribe(cmd *cobra.Command, args []string) (err error) {
5658

5759
// Check if the Function has been initialized
5860
if !function.Initialized() {
59-
return fmt.Errorf("the given path '%v' does not contain an initialized Function.", config.Path)
61+
return fmt.Errorf("the given path '%v' does not contain an initialized function", config.Path)
6062
}
6163

6264
describer, err := knative.NewDescriber(config.Namespace)

0 commit comments

Comments
 (0)