Skip to content

Commit

Permalink
Merge pull request #4 from icy/helm_command_without_separator
Browse files Browse the repository at this point in the history
helm command doesnot need separator (--)
  • Loading branch information
icy authored May 2, 2023
2 parents ce8476d + 459d540 commit 98f2db3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ This new way

```
$ gk8s :my-cluster get nodes
$ gk8s :my-cluster helm list
$ gk8s :my-cluster -- helm list
$ gk8s :my-cluster -- custom-command # KUBECONFIG will be set accordingly with default context!
```
Expand Down Expand Up @@ -94,8 +95,8 @@ You get no idea of the cluster on which you executed the command(s).

## Getting started

Starting from v1.1.1, you can download binary files generated automatically
by Github-Action (via goreleaser tool). You find the files from
Starting from v1.1.1, you can download binary files generated automatically
by Github-Action (via goreleaser tool). You find the files from
the release listing page: https://github.com/icy/gk8s/releases

To install on your laptop by local compiling process, please try the popular way
Expand Down Expand Up @@ -139,6 +140,14 @@ $ gk8s :cluster kubectl get nodes
$ gk8s :cluster -- kubectl get nodes
```

Both `kubectl` and `helm` don't need any separator (`--`). The following
commands are the same:

```
$ gk8s :cluster helm list
$ gk8s :cluster -- helm list
```

Some notes

* The command `kubectl` is used by default.
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/icy/gk8s

go 1.20
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ func args2cmd(args []string) (string, []string) {
return command, []string{""}
}
} else {
if strings.Index(args[0], "kubectl") == -1 {
if strings.Index(args[0], "helm") == 0 {
command = "helm"
args = args[0:]
} else if strings.Index(args[0], "kubectl") == -1 {
command = "kubectl"
args = append([]string{command}, args...)
} else {
Expand Down
19 changes: 18 additions & 1 deletion tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Author : Ky-Anh Huynh
# License : Public domain


_gk8s() {
"$(pwd -P)"/gk8s "${@}"
}
Expand All @@ -24,6 +25,15 @@ _fail_when_command_not_found() {
_gk8s :any_name -- foo/bar xyz
}

# NOTE: helm command is required.
_fail_with_helm_repo_list() {
(
export HELM_REPOSITORY_CONFIG=/dev/null
touch ~/.config/gk8s/helm_test
_gk8s :helm_test helm repo list
)
}

# NOTE: kubectl command is required.
_fail_with_cluster_config_not_found() {
(
Expand Down Expand Up @@ -118,6 +128,9 @@ _ok_to_delete_with_env_flag() {
)
}

# $1: function to test
# $2: regular expression
# $*: Test description
_test() {
fun="$1"; shift
reg="$1"; shift
Expand Down Expand Up @@ -148,7 +161,7 @@ _test() {

default() {
ln -sfv /bin/true kubectl
mkdir -p ~/.config/gk8s
mkdir -pv ~/.config/gk8s

_test _fail_when_command_not_found \
"Command not found" \
Expand Down Expand Up @@ -205,6 +218,10 @@ default() {
_test _ok_to_delete_with_env_flag \
"Executing.*kubectl delete pods" \
"Now executing actual delete command."

_test _fail_with_helm_repo_list \
"Error: no repositories to show" \
"helm would not need any separator (--)."
}

### main routines ######################################################
Expand Down

0 comments on commit 98f2db3

Please sign in to comment.