Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pradeepmurugesan committed Oct 15, 2019
1 parent 2fa1f95 commit 4f5d20c
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
32 changes: 32 additions & 0 deletions app/kumactl/cmd/delete/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package delete

import (
kumactl_cmd "github.com/Kong/kuma/app/kumactl/pkg/cmd"
"github.com/Kong/kuma/app/kumactl/pkg/output"
"github.com/spf13/cobra"
kuma_cmd "github.com/Kong/kuma/pkg/cmd"
)

type deleteContext struct {
*kumactl_cmd.RootContext

args struct {
outputFormat string
}
}

func NewDeleteCmd(pctx *kumactl_cmd.RootContext) *cobra.Command {
ctx := &deleteContext{RootContext: pctx}
cmd := &cobra.Command{
Use: "delete",
Short: "Delete Kuma resources",
Long: `Delete Kuma resources.`,
}
// flags
cmd.PersistentFlags().StringVarP(&ctx.args.outputFormat, "output", "o", string(output.TableFormat), kuma_cmd.UsageOptions("output format", output.TableFormat, output.YAMLFormat, output.JSONFormat))
// sub-commands

cmd.AddCommand(newSayHelloCmd(ctx))
cmd.AddCommand(newDeleteMeshCmd(ctx))
return cmd
}
37 changes: 37 additions & 0 deletions app/kumactl/cmd/delete/delete_meshes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package delete

import (
"context"
"fmt"
"github.com/Kong/kuma/pkg/core/resources/apis/mesh"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

func newDeleteMeshCmd(pctx *deleteContext) *cobra.Command {
cmd := &cobra.Command{
Use: "mesh",
Short: "Delete Mesh",
Long: `Delete Mesh.`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
rs, err := pctx.CurrentResourceStore()
if err != nil {
fmt.Println("Error occurred when getting store")
return err
}
meshName := args[0]

mesh := mesh.MeshResource{}
if err := rs.Get(context.Background(), &mesh); err != nil {
fmt.Println("Error occurred")
return errors.Wrapf(err, "failed to get Mesh with the name " + meshName)
}

fmt.Println("No Error occurred to get Mesh with the name " + meshName)
fmt.Print(fmt.Sprintf("Mesh: %v", mesh))
return nil
},
}
return cmd
}
33 changes: 33 additions & 0 deletions app/kumactl/cmd/delete/say_hello.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package delete

import (
"fmt"
"github.com/spf13/cobra"
)

type sayHelloContext struct {
*deleteContext

tagsArgs struct {
tags map[string]string
}
}

func newSayHelloCmd(pctx *deleteContext) *cobra.Command {

ctx := sayHelloContext{
deleteContext: pctx,
}

cmd := &cobra.Command{
Use: "hello",
Short: "Say Hello",
Long: `Say Hello.`,
RunE: func(cmd *cobra.Command, _ []string) error {
fmt.Println("Hello")
return nil
},
}
cmd.PersistentFlags().StringToStringVarP(&ctx.tagsArgs.tags, "tag", "", map[string]string{}, "filter by tag in format of key=value. You can provide many tags")
return cmd
}
2 changes: 2 additions & 0 deletions app/kumactl/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/Kong/kuma/app/kumactl/cmd/apply"
"github.com/Kong/kuma/app/kumactl/cmd/config"
"github.com/Kong/kuma/app/kumactl/cmd/get"
del "github.com/Kong/kuma/app/kumactl/cmd/delete"
"github.com/Kong/kuma/app/kumactl/cmd/inspect"
"github.com/Kong/kuma/app/kumactl/cmd/install"
kumactl_cmd "github.com/Kong/kuma/app/kumactl/pkg/cmd"
Expand Down Expand Up @@ -59,6 +60,7 @@ func NewRootCmd(root *kumactl_cmd.RootContext) *cobra.Command {
cmd.AddCommand(install.NewInstallCmd(root))
cmd.AddCommand(config.NewConfigCmd(root))
cmd.AddCommand(get.NewGetCmd(root))
cmd.AddCommand(del.NewDeleteCmd(root))
cmd.AddCommand(inspect.NewInspectCmd(root))
cmd.AddCommand(apply.NewApplyCmd(root))
cmd.AddCommand(version.NewVersionCmd())
Expand Down

0 comments on commit 4f5d20c

Please sign in to comment.