Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minot improvements to kamel client #81

Merged
merged 2 commits into from
Sep 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions pkg/client/cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/spf13/cobra"
)

const completionCmdLongDescription = `
const bashCompletionCmdLongDescription = `
To load completion run

. <(kamel completion)
Expand All @@ -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
}
27 changes: 20 additions & 7 deletions pkg/client/cmd/context_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down
19 changes: 14 additions & 5 deletions pkg/client/cmd/context_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
6 changes: 3 additions & 3 deletions pkg/client/cmd/context_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down