-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2fa1f95
commit 4f5d20c
Showing
4 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters