Skip to content

Commit 385c8fb

Browse files
committed
feat: add crud and other basic commands
This commit adds a couple of useful commands straight from the kubectl library. This is useful to validate reusable part of the program and needed abstractions. A partial list of commands added in this PR are: * diff * apply * create * explain * delete * edit
1 parent 7150a73 commit 385c8fb

File tree

5 files changed

+43
-50
lines changed

5 files changed

+43
-50
lines changed

internal/cmd/api-resources/api-resources.go

Lines changed: 0 additions & 12 deletions
This file was deleted.

internal/cmd/api-resources/api-versions.go

Lines changed: 0 additions & 12 deletions
This file was deleted.

internal/cmd/get/get.go

Lines changed: 0 additions & 21 deletions
This file was deleted.

internal/cmd/root.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@ package cmd
33
import (
44
"github.com/spf13/cobra"
55
"go.datum.net/datumctl/internal/client"
6-
apiresources "go.datum.net/datumctl/internal/cmd/api-resources"
76
"go.datum.net/datumctl/internal/cmd/auth"
8-
"go.datum.net/datumctl/internal/cmd/get"
97
"go.datum.net/datumctl/internal/cmd/mcp"
108
"k8s.io/cli-runtime/pkg/genericclioptions"
9+
"k8s.io/kubectl/pkg/cmd/apiresources"
10+
"k8s.io/kubectl/pkg/cmd/apply"
11+
"k8s.io/kubectl/pkg/cmd/clusterinfo"
12+
"k8s.io/kubectl/pkg/cmd/create"
13+
delcmd "k8s.io/kubectl/pkg/cmd/delete"
14+
"k8s.io/kubectl/pkg/cmd/describe"
15+
"k8s.io/kubectl/pkg/cmd/diff"
16+
"k8s.io/kubectl/pkg/cmd/edit"
17+
"k8s.io/kubectl/pkg/cmd/explain"
18+
"k8s.io/kubectl/pkg/cmd/get"
1119
)
1220

1321
func RootCmd() *cobra.Command {
@@ -34,9 +42,21 @@ func RootCmd() *cobra.Command {
3442
}
3543
factory.AddFlags(rootCmd.PersistentFlags())
3644
rootCmd.AddCommand(auth.Command())
37-
rootCmd.AddCommand(get.Command(factory, ioStreams))
38-
rootCmd.AddCommand(apiresources.Command(factory, ioStreams))
39-
rootCmd.AddCommand(apiresources.CommandApiResources(factory, ioStreams))
45+
46+
rootCmd.AddCommand(WrapResourceCommand(get.NewCmdGet("datumctl", factory, ioStreams)))
47+
rootCmd.AddCommand(WrapResourceCommand(delcmd.NewCmdDelete(factory, ioStreams)))
48+
rootCmd.AddCommand(create.NewCmdCreate(factory, ioStreams))
49+
rootCmd.AddCommand(apply.NewCmdApply("datumctl", factory, ioStreams))
50+
rootCmd.AddCommand(WrapResourceCommand(edit.NewCmdEdit(factory, ioStreams)))
51+
rootCmd.AddCommand(WrapResourceCommand(describe.NewCmdDescribe("datumctl", factory, ioStreams)))
52+
53+
rootCmd.AddCommand(diff.NewCmdDiff(factory, ioStreams))
54+
rootCmd.AddCommand(explain.NewCmdExplain("datumctl", factory, ioStreams))
55+
56+
rootCmd.AddCommand(apiresources.NewCmdAPIVersions(factory, ioStreams))
57+
rootCmd.AddCommand(clusterinfo.NewCmdClusterInfo(factory, ioStreams))
58+
rootCmd.AddCommand(apiresources.NewCmdAPIResources(factory, ioStreams))
59+
4060
rootCmd.AddCommand(mcp.Command())
4161
return rootCmd
4262
}

internal/cmd/utils.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package cmd
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
)
6+
7+
func WrapResourceCommand(cmd *cobra.Command) *cobra.Command {
8+
preRunFunc := func(cmd *cobra.Command, args []string) error {
9+
// This mapping helps user during the getting started phase
10+
if args[0] == "organizations" || args[0] == "organization" {
11+
args[0] = "organizationmemberships"
12+
cmd.Flag("all-namespaces").Value.Set("true")
13+
}
14+
return nil
15+
}
16+
cmd.PreRunE = preRunFunc
17+
return cmd
18+
}

0 commit comments

Comments
 (0)