oscerd closed pull request #81: Minot improvements to kamel client
URL: https://github.com/apache/camel-k/pull/81
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/pkg/client/cmd/completion.go b/pkg/client/cmd/completion.go
index f86bd0b..e172df0 100644
--- a/pkg/client/cmd/completion.go
+++ b/pkg/client/cmd/completion.go
@@ -23,7 +23,7 @@ import (
"github.com/spf13/cobra"
)
-const completionCmdLongDescription = `
+const bashCompletionCmdLongDescription = `
To load completion run
. <(kamel completion)
@@ -34,14 +34,38 @@ To configure your bash shell to load completions for each
session add to your ba
. <(kamel completion)
`
+const zshCompletionCmdLongDescription = `
+To configure your zsh shell to load completions for each session add to your
zshrc
+
+if [ $commands[kamel] ]; then
+ source <(kamel completion zsh)
+fi
+`
+
// NewCmdCompletion --
func NewCmdCompletion(root *cobra.Command) *cobra.Command {
- return &cobra.Command{
+ completion := cobra.Command{
Use: "completion",
+ Short: "Generates completion scripts",
+ }
+
+ completion.AddCommand(&cobra.Command{
+ Use: "bash",
Short: "Generates bash completion scripts",
- Long: completionCmdLongDescription,
+ Long: bashCompletionCmdLongDescription,
Run: func(cmd *cobra.Command, args []string) {
root.GenBashCompletion(os.Stdout)
},
- }
+ })
+
+ completion.AddCommand(&cobra.Command{
+ Use: "zsh",
+ Short: "Generates zsh completion scripts",
+ Long: zshCompletionCmdLongDescription,
+ Run: func(cmd *cobra.Command, args []string) {
+ root.GenZshCompletion(os.Stdout)
+ },
+ })
+
+ return &completion
}
diff --git a/pkg/client/cmd/context_create.go b/pkg/client/cmd/context_create.go
index 49c3950..224f1e0 100644
--- a/pkg/client/cmd/context_create.go
+++ b/pkg/client/cmd/context_create.go
@@ -71,10 +71,21 @@ func (command *contextCreateCommand) validateArgs(cmd
*cobra.Command, args []str
}
func (command *contextCreateCommand) run(cmd *cobra.Command, args []string)
error {
- namespace := command.Namespace
- name := kubernetes.SanitizeName(args[0])
+ ctx := v1alpha1.NewIntegrationContext(command.Namespace, args[0])
+ if err := sdk.Get(&ctx); err == nil {
+ // the integration context already exists, let's check that it
is
+ // not a platform one which is supposed to be "read only"
+
+ if ctx.Labels["camel.apache.org/context.type"] == "platform" {
+ fmt.Printf("integration context \"%s\" is not
editable\n", ctx.Name)
+ return nil
+ }
+ }
- ctx := v1alpha1.NewIntegrationContext(namespace, name)
+ ctx = v1alpha1.NewIntegrationContext(command.Namespace,
kubernetes.SanitizeName(args[0]))
+ ctx.Labels = map[string]string{
+ "camel.apache.org/context.type": "user",
+ }
ctx.Spec = v1alpha1.IntegrationContextSpec{
Dependencies: command.dependencies,
Configuration: make([]v1alpha1.ConfigurationSpec, 0),
@@ -106,20 +117,22 @@ func (command *contextCreateCommand) run(cmd
*cobra.Command, args []string) erro
clone := ctx.DeepCopy()
err = sdk.Get(clone)
if err != nil {
- return err
+ fmt.Printf(err.Error())
+ return nil
}
ctx.ResourceVersion = clone.ResourceVersion
err = sdk.Update(&ctx)
}
if err != nil {
- return err
+ fmt.Printf(err.Error())
+ return nil
}
if !existed {
- fmt.Printf("integration context \"%s\" created\n", name)
+ fmt.Printf("integration context \"%s\" created\n", ctx.Name)
} else {
- fmt.Printf("integration context \"%s\" updated\n", name)
+ fmt.Printf("integration context \"%s\" updated\n", ctx.Name)
}
return nil
diff --git a/pkg/client/cmd/context_delete.go b/pkg/client/cmd/context_delete.go
index c4cb893..be77d09 100644
--- a/pkg/client/cmd/context_delete.go
+++ b/pkg/client/cmd/context_delete.go
@@ -23,7 +23,6 @@ import (
"strconv"
"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
- "github.com/apache/camel-k/pkg/util/kubernetes"
"github.com/operator-framework/operator-sdk/pkg/sdk"
"github.com/spf13/cobra"
)
@@ -57,15 +56,25 @@ func (command *contextDeleteCommand) validateArgs(cmd
*cobra.Command, args []str
}
func (command *contextDeleteCommand) run(cmd *cobra.Command, args []string)
error {
- name := kubernetes.SanitizeName(args[0])
- ctx := v1alpha1.NewIntegrationContext(command.Namespace, name)
+ ctx := v1alpha1.NewIntegrationContext(command.Namespace, args[0])
+
+ if err := sdk.Get(&ctx); err != nil {
+ return err
+ }
+
+ // let's check that it is not a platform one which is supposed to be
"read only"
+ // thus not managed by the end user
+ if ctx.Labels["camel.apache.org/context.type"] == "platform" {
+ fmt.Printf("integration context \"%s\" is not editable\n",
ctx.Name)
+ return nil
+ }
if err := sdk.Delete(&ctx); err != nil {
- fmt.Printf("error deleting integration context %s, %s",
ctx.Name, err)
+ fmt.Printf("error deleting integration context \"%s\", %s\n",
ctx.Name, err)
return err
}
- fmt.Printf("integration context %s has been deleted", ctx.Name)
+ fmt.Printf("integration context \"%s\" has been deleted\n", ctx.Name)
return nil
}
diff --git a/pkg/client/cmd/context_get.go b/pkg/client/cmd/context_get.go
index 05a96ca..0a487b2 100644
--- a/pkg/client/cmd/context_get.go
+++ b/pkg/client/cmd/context_get.go
@@ -52,10 +52,10 @@ func (command *contextGetCommand) run(cmd *cobra.Command,
args []string) error {
return err
}
- w := tabwriter.NewWriter(os.Stdout, 0, 8, 0, '\t', 0)
- fmt.Fprintln(w, "NAME\tSTATUS")
+ w := tabwriter.NewWriter(os.Stdout, 0, 8, 1, '\t', 0)
+ fmt.Fprintln(w, "NAME\tTYPE\tSTATUS")
for _, ctx := range ctxList.Items {
- fmt.Fprintf(w, "%s\t%s\n", ctx.Name, string(ctx.Status.Phase))
+ fmt.Fprintf(w, "%s\t%s\t%s\n", ctx.Name,
ctx.Labels["camel.apache.org/context.type"], string(ctx.Status.Phase))
}
w.Flush()
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services