Skip to content

Commit

Permalink
Merge pull request #9 from DomineCore/develop
Browse files Browse the repository at this point in the history
minor: cluster commnad -> console command
  • Loading branch information
DomineCore authored Jun 16, 2023
2 parents 00ab9d3 + bf5ea0c commit bf1368d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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。
Expand All @@ -20,7 +21,7 @@ export PATH=$PATH:/usr/local/bin
在命令行中运行以下命令:

```
kconsole cluster
kconsole console
```
这将显示一个交互式菜单,列出了 Kubernetes 集群中的所有 Pod以及它们所在的namespace。

Expand All @@ -37,6 +38,13 @@ kconsole 支持以下选项:

-h, --help: 显示帮助信息。

## 子命令
kconsole 提供以下子命令:

console: 进入集群中的容器终端
download: 下载集群中的容器内文件
upload: 上传本地文件到集群中的容器

## 开发
如果您想要为 kconsole 做出贡献,或者想要构建自己的版本,请按照以下步骤操作:

Expand Down
2 changes: 1 addition & 1 deletion cmd/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions cmd/cluster.go → cmd/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
22 changes: 11 additions & 11 deletions cmd/cluster_test.go → cmd/console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit bf1368d

Please sign in to comment.