diff --git a/README.md b/README.md index 7a34ab9..abd994c 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ # kconsole -kconsole 是一个用于快速进入 Kubernetes 集群容器终端的命令行工具。它使用 client-go 来获取 Kubernetes 集群中的 Pod 和容器信息,并使用 exec 命令进入容器终端。 + +kconsole 是一个用于与提高 Kubernetes 集群容器交互效率的命令行工具。它使用client-go 来与 Kubernetes 集群交互,提供快速进入容器终端、下载容器文件、上传本地文件到容器等便捷功能。 ## 使用 -要使用 kconsole 进入 Kubernetes 集群中的容器终端,请按照以下步骤操作: +以 console 子命令为例,要使用 kconsole 进入 Kubernetes 集群中的容器终端,请按照以下步骤操作: ### 1 下载 kconsole 可执行文件。 您可以从 GitHub Releases 页面 下载最新版本的 kconsole。 @@ -20,7 +21,7 @@ export PATH=$PATH:/usr/local/bin 在命令行中运行以下命令: ``` -kconsole cluster +kconsole console ``` 这将显示一个交互式菜单,列出了 Kubernetes 集群中的所有 Pod以及它们所在的namespace。 @@ -37,6 +38,13 @@ kconsole 支持以下选项: -h, --help: 显示帮助信息。 +## 子命令 +kconsole 提供以下子命令: + +console: 进入集群中的容器终端 +download: 下载集群中的容器内文件 +upload: 上传本地文件到集群中的容器 + ## 开发 如果您想要为 kconsole 做出贡献,或者想要构建自己的版本,请按照以下步骤操作: diff --git a/cmd/command.go b/cmd/command.go index 3a308d0..0330bf4 100644 --- a/cmd/command.go +++ b/cmd/command.go @@ -52,7 +52,7 @@ func NewBaseCommand() *BaseCommand { baseCmd := &BaseCommand{ command: cli.rootCmd, } - baseCmd.AddCommands(&ClusterCmd{}) + baseCmd.AddCommands(&ConsoleCmd{}) baseCmd.AddCommands(&DownloadCmd{}) baseCmd.AddCommands(&UploadCmd{}) return baseCmd diff --git a/cmd/cluster.go b/cmd/console.go similarity index 92% rename from cmd/cluster.go rename to cmd/console.go index 06391cd..ce4721d 100644 --- a/cmd/cluster.go +++ b/cmd/console.go @@ -29,23 +29,23 @@ import ( var CMDS = []string{"sh", "bash"} -type ClusterCmd struct { +type ConsoleCmd struct { BaseCommand } -func (cl *ClusterCmd) Init() { +func (cl *ConsoleCmd) Init() { cl.command = &cobra.Command{ - Use: "cluster", + Use: "console", Short: "Exec a command for a container incluster.", Long: "Exec a command for a container incluster.", RunE: func(cmd *cobra.Command, args []string) error { - return cl.runCluster(cmd, args) + return cl.runConsole(cmd, args) }, } cl.command.DisableFlagsInUseLine = true } -func (cl ClusterCmd) runCluster(cmd *cobra.Command, args []string) error { +func (cl ConsoleCmd) runConsole(cmd *cobra.Command, args []string) error { // call utils get pods pods := ListAllPods() selectpod := SelectUI(pods, "select a pod") diff --git a/cmd/cluster_test.go b/cmd/console_test.go similarity index 69% rename from cmd/cluster_test.go rename to cmd/console_test.go index 2498914..b8210d8 100644 --- a/cmd/cluster_test.go +++ b/cmd/console_test.go @@ -27,22 +27,22 @@ import ( "github.com/stretchr/testify/assert" ) -func TestClusterCmd_Init(t *testing.T) { +func TestConsoleCmd_Init(t *testing.T) { // Create a mock BaseCommand baseCmd := &BaseCommand{} - // Create a ClusterCmd with the mock BaseCommand - clusterCmd := &ClusterCmd{ + // Create a ConsoleCmd with the mock BaseCommand + ConsoleCmd := &ConsoleCmd{ BaseCommand: *baseCmd, } - // Call Init on the ClusterCmd - clusterCmd.Init() + // Call Init on the ConsoleCmd + ConsoleCmd.Init() - // Check that the ClusterCmd's command has the expected Use, Short, and Long fields - assert.Equal(t, "cluster", clusterCmd.command.Use) - assert.Equal(t, "Exec a command for a container incluster.", clusterCmd.command.Short) - assert.Equal(t, "Exec a command for a container incluster.", clusterCmd.command.Long) - assert.True(t, clusterCmd.command.DisableFlagsInUseLine) - assert.NotNil(t, clusterCmd.command.RunE) + // Check that the ConsoleCmd's command has the expected Use, Short, and Long fields + assert.Equal(t, "console", ConsoleCmd.command.Use) + assert.Equal(t, "Exec a command for a container incluster.", ConsoleCmd.command.Short) + assert.Equal(t, "Exec a command for a container incluster.", ConsoleCmd.command.Long) + assert.True(t, ConsoleCmd.command.DisableFlagsInUseLine) + assert.NotNil(t, ConsoleCmd.command.RunE) }