diff --git a/README.md b/README.md index 39caa87..ccb7b99 100644 --- a/README.md +++ b/README.md @@ -203,6 +203,7 @@ ln -s /mnt/c/Users//.kube/config ~/.kube/config ```bash kctl-tui # start the TUI (full navigation mode) +kctl-tui --help # show all commands and flags kctl-tui --version # print version kctl-tui --verbose # enable debug logging to stderr kctl-tui doctor # check if all tools, config and connections are OK diff --git a/cmd/kctl-tui/full.go b/cmd/kctl-tui/full.go index 1608176..b6d893e 100644 --- a/cmd/kctl-tui/full.go +++ b/cmd/kctl-tui/full.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "os" "os/exec" "sort" @@ -265,7 +266,10 @@ func (m *fullModel) loadNamespacesFor(teamValue string) tea.Cmd { // configured envs, resolved via the context template, so both are // visible side by side. func (m *fullModel) startTmuxSession() tea.Cmd { - selfPath := "kctl-tui" + selfPath, err := os.Executable() + if err != nil { + selfPath = "kctl-tui" // fallback to PATH lookup + } panelCmd := fmt.Sprintf("%s panel --context=%s --ns=%s --team=%s", selfPath, m.selectedContext, m.selectedNamespace, m.selectedTeam) diff --git a/cmd/kctl-tui/main.go b/cmd/kctl-tui/main.go index 120b008..ea542de 100644 --- a/cmd/kctl-tui/main.go +++ b/cmd/kctl-tui/main.go @@ -18,6 +18,7 @@ func main() { // Extract global flags before delegating to sub-commands. verbose := false + showHelp := false filtered := make([]string, 0, len(args)) for _, a := range args { switch a { @@ -26,6 +27,8 @@ func main() { case "--version", "-v": fmt.Printf("kctl-tui %s\n", version) return + case "--help", "-h": + showHelp = true default: filtered = append(filtered, a) } @@ -34,6 +37,13 @@ func main() { kubeexec.SetVerbose(true, os.Stderr) } + if showHelp || len(filtered) == 0 { + printUsage() + if showHelp && len(filtered) == 0 { + return + } + } + if len(filtered) > 0 { switch filtered[0] { case "panel": @@ -65,6 +75,28 @@ func main() { } } +func printUsage() { + fmt.Print(`kctl-tui — Kubernetes entry-point TUI + +Usage: + kctl-tui [flags] start the TUI (full navigation mode) + kctl-tui doctor check tools, config and connections + kctl-tui config check validate ~/.kctl-tui/config.yaml + kctl-tui panel [options] control pane (called internally by tmux) + +Flags: + --verbose log all kubectl/aws commands to stderr + --version print version + --help show this help + +Examples: + kctl-tui # start the TUI + kctl-tui doctor # verify everything is installed + kctl-tui --verbose 2>debug.log # log commands to a file + kctl-tui config check # validate config +`) +} + func runConfig(args []string) error { if len(args) == 0 || args[0] != "check" { return fmt.Errorf("usage: kctl-tui config check")