Skip to content

Commit

Permalink
feat Allow silencing context table upon config write
Browse files Browse the repository at this point in the history
  • Loading branch information
dennislapchenko committed Nov 1, 2023
1 parent 5db7213 commit ffbf49d
Show file tree
Hide file tree
Showing 19 changed files with 48 additions and 29 deletions.
8 changes: 5 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ import (
)

var (
cfgFile string
uiSize int
macNotify bool
cfgFile string
uiSize int
macNotify bool
silenceTable bool
)

// Cli cmd struct
Expand Down Expand Up @@ -64,6 +65,7 @@ func (cli *Cli) setFlags() {
flags := cli.rootCmd.PersistentFlags()
flags.StringVar(&cfgFile, "config", *kubeconfig, "path of kubeconfig")
flags.IntVar(&uiSize, "ui-size", 4, "number of list items to show in menu at once")
flags.BoolVarP(&silenceTable, "silence-table", "s", false, "enable/disable output of context table on successful config update")
flags.BoolVarP(&macNotify, "mac-notify", "m", false, "enable to display Mac notification banner")
}

Expand Down
10 changes: 7 additions & 3 deletions cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,14 @@ func WriteConfig(cover bool, file string, outConfig *clientcmdapi.Config) error
return err
}
fmt.Printf("「%s」 write successful!\n", file)
err = PrintTable(outConfig)
if err != nil {
return err

if !silenceTable {
err = PrintTable(outConfig)
if err != nil {
return err
}
}

} else {
err := clientcmd.WriteToFile(*outConfig, "kubecm.config")
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions docs/en-us/cli/kubecm.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ KubeConfig Manager.
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ 
██ ██ ██████ ██████ ███████ ██████ ██ ██

[44;97m[44;97m Tips [0m[0m [96m[96mFind more information at: [3;32mkubecm.cloud (https://kubecm.cloud)[m[0m[0m
[44;97m[44;97m Tips [0m[0m [96m[96mFind more information at: ]8;;https://kubecm.cloud[3;32mkubecm.cloud]8;;[0m[96m[0m[0m


### Options

```
--config string path of kubeconfig (default "/Users/guoxudong/.kube/config")
--config string path of kubeconfig (default "/Users/user/.kube/config")
-h, --help help for kubecm
-m, --mac-notify enable to display Mac notification banner
-s, --silence-table enable/disable output of context table on successful config update
--ui-size int number of list items to show in menu at once (default 4)
```

Expand Down
3 changes: 2 additions & 1 deletion docs/en-us/cli/kubecm_add.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ cat /etc/kubernetes/admin.conf | kubecm add -f -
### Options inherited from parent commands

```
--config string path of kubeconfig (default "/Users/guoxudong/.kube/config")
--config string path of kubeconfig (default "/Users/user/.kube/config")
-m, --mac-notify enable to display Mac notification banner
-s, --silence-table enable/disable output of context table on successful config update
--ui-size int number of list items to show in menu at once (default 4)
```

Expand Down
3 changes: 2 additions & 1 deletion docs/en-us/cli/kubecm_alias.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ $ kubecm alias -o bash
### Options inherited from parent commands

```
--config string path of kubeconfig (default "/Users/guoxudong/.kube/config")
--config string path of kubeconfig (default "/Users/user/.kube/config")
-m, --mac-notify enable to display Mac notification banner
-s, --silence-table enable/disable output of context table on successful config update
--ui-size int number of list items to show in menu at once (default 4)
```

Expand Down
5 changes: 3 additions & 2 deletions docs/en-us/cli/kubecm_clear.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ kubecm clear

```
# Clear lapsed context, cluster and user (default is /Users/guoxudong/.kube/config)
# Clear lapsed context, cluster and user (default is /Users/user/.kube/config)
kubecm clear
# Customised clear lapsed files
kubecm clear config.yaml test.yaml
Expand All @@ -30,8 +30,9 @@ kubecm clear config.yaml test.yaml
### Options inherited from parent commands

```
--config string path of kubeconfig (default "/Users/guoxudong/.kube/config")
--config string path of kubeconfig (default "/Users/user/.kube/config")
-m, --mac-notify enable to display Mac notification banner
-s, --silence-table enable/disable output of context table on successful config update
--ui-size int number of list items to show in menu at once (default 4)
```

Expand Down
3 changes: 2 additions & 1 deletion docs/en-us/cli/kubecm_cloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ Manage kubeconfig from cloud
### Options inherited from parent commands

```
--config string path of kubeconfig (default "/Users/guoxudong/.kube/config")
--config string path of kubeconfig (default "/Users/user/.kube/config")
-m, --mac-notify enable to display Mac notification banner
-s, --silence-table enable/disable output of context table on successful config update
--ui-size int number of list items to show in menu at once (default 4)
```

Expand Down
3 changes: 2 additions & 1 deletion docs/en-us/cli/kubecm_cloud_add.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ kubecm cloud add --provider alibabacloud --cluster_id=xxxxxx

```
--cluster_id string kubernetes cluster id
--config string path of kubeconfig (default "/Users/guoxudong/.kube/config")
--config string path of kubeconfig (default "/Users/user/.kube/config")
-m, --mac-notify enable to display Mac notification banner
--provider string public cloud
--region_id string cloud region id
-s, --silence-table enable/disable output of context table on successful config update
--ui-size int number of list items to show in menu at once (default 4)
```

Expand Down
3 changes: 2 additions & 1 deletion docs/en-us/cli/kubecm_cloud_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ kubecm cloud list --provider alibabacloud --cluster_id=xxxxxx

```
--cluster_id string kubernetes cluster id
--config string path of kubeconfig (default "/Users/guoxudong/.kube/config")
--config string path of kubeconfig (default "/Users/user/.kube/config")
-m, --mac-notify enable to display Mac notification banner
--provider string public cloud
--region_id string cloud region id
-s, --silence-table enable/disable output of context table on successful config update
--ui-size int number of list items to show in menu at once (default 4)
```

Expand Down
3 changes: 2 additions & 1 deletion docs/en-us/cli/kubecm_completion.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ kubecm completion [bash|zsh|fish|powershell] [flags]
### Options inherited from parent commands

```
--config string path of kubeconfig (default "/Users/guoxudong/.kube/config")
--config string path of kubeconfig (default "/Users/user/.kube/config")
-m, --mac-notify enable to display Mac notification banner
-s, --silence-table enable/disable output of context table on successful config update
--ui-size int number of list items to show in menu at once (default 4)
```

Expand Down
3 changes: 2 additions & 1 deletion docs/en-us/cli/kubecm_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ kubecm create
### Options inherited from parent commands

```
--config string path of kubeconfig (default "/Users/guoxudong/.kube/config")
--config string path of kubeconfig (default "/Users/user/.kube/config")
-m, --mac-notify enable to display Mac notification banner
-s, --silence-table enable/disable output of context table on successful config update
--ui-size int number of list items to show in menu at once (default 4)
```

Expand Down
3 changes: 2 additions & 1 deletion docs/en-us/cli/kubecm_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ kubecm delete my-context1 my-context2
### Options inherited from parent commands

```
--config string path of kubeconfig (default "/Users/guoxudong/.kube/config")
--config string path of kubeconfig (default "/Users/user/.kube/config")
-m, --mac-notify enable to display Mac notification banner
-s, --silence-table enable/disable output of context table on successful config update
--ui-size int number of list items to show in menu at once (default 4)
```

Expand Down
3 changes: 2 additions & 1 deletion docs/en-us/cli/kubecm_export.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ kubecm export -f myconfig.yaml my-context1 my-context2
### Options inherited from parent commands

```
--config string path of kubeconfig (default "/Users/guoxudong/.kube/config")
--config string path of kubeconfig (default "/Users/user/.kube/config")
-m, --mac-notify enable to display Mac notification banner
-s, --silence-table enable/disable output of context table on successful config update
--ui-size int number of list items to show in menu at once (default 4)
```

Expand Down
3 changes: 2 additions & 1 deletion docs/en-us/cli/kubecm_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ kubecm ls kind k3s
### Options inherited from parent commands

```
--config string path of kubeconfig (default "/Users/guoxudong/.kube/config")
--config string path of kubeconfig (default "/Users/user/.kube/config")
-m, --mac-notify enable to display Mac notification banner
-s, --silence-table enable/disable output of context table on successful config update
--ui-size int number of list items to show in menu at once (default 4)
```

Expand Down
3 changes: 2 additions & 1 deletion docs/en-us/cli/kubecm_merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ kubecm merge -f dir --config kubecm.config
### Options inherited from parent commands

```
--config string path of kubeconfig (default "/Users/guoxudong/.kube/config")
--config string path of kubeconfig (default "/Users/user/.kube/config")
-m, --mac-notify enable to display Mac notification banner
-s, --silence-table enable/disable output of context table on successful config update
--ui-size int number of list items to show in menu at once (default 4)
```

Expand Down
5 changes: 2 additions & 3 deletions docs/en-us/cli/kubecm_namespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ Switch or change namespace interactively
kubecm namespace [flags]
```

![ns](../../static/ns.gif)

### Examples

```
Expand All @@ -36,8 +34,9 @@ kubecm ns kube-system
### Options inherited from parent commands

```
--config string path of kubeconfig (default "/Users/guoxudong/.kube/config")
--config string path of kubeconfig (default "/Users/user/.kube/config")
-m, --mac-notify enable to display Mac notification banner
-s, --silence-table enable/disable output of context table on successful config update
--ui-size int number of list items to show in menu at once (default 4)
```

Expand Down
3 changes: 2 additions & 1 deletion docs/en-us/cli/kubecm_rename.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ kubecm rename
### Options inherited from parent commands

```
--config string path of kubeconfig (default "/Users/guoxudong/.kube/config")
--config string path of kubeconfig (default "/Users/user/.kube/config")
-m, --mac-notify enable to display Mac notification banner
-s, --silence-table enable/disable output of context table on successful config update
--ui-size int number of list items to show in menu at once (default 4)
```

Expand Down
5 changes: 2 additions & 3 deletions docs/en-us/cli/kubecm_switch.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ Switch Kube Context interactively
kubecm switch [flags]
```

![switch](../../static/switch.gif)

### Examples

```
Expand All @@ -34,8 +32,9 @@ kubecm switch dev
### Options inherited from parent commands

```
--config string path of kubeconfig (default "/Users/guoxudong/.kube/config")
--config string path of kubeconfig (default "/Users/user/.kube/config")
-m, --mac-notify enable to display Mac notification banner
-s, --silence-table enable/disable output of context table on successful config update
--ui-size int number of list items to show in menu at once (default 4)
```

Expand Down
3 changes: 2 additions & 1 deletion docs/en-us/cli/kubecm_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ kubecm version [flags]
### Options inherited from parent commands

```
--config string path of kubeconfig (default "/Users/guoxudong/.kube/config")
--config string path of kubeconfig (default "/Users/user/.kube/config")
-m, --mac-notify enable to display Mac notification banner
-s, --silence-table enable/disable output of context table on successful config update
--ui-size int number of list items to show in menu at once (default 4)
```

Expand Down

0 comments on commit ffbf49d

Please sign in to comment.