feat: add uc ctx show command to print the current cluster context (#317)

* feat: add uc ctx show

This only shows the current context and nothing more. On error nothing
is printed (also no error). This is useful to include in your prompt.

See: #314

Signed-off-by: Miek Gieben <miek@miek.nl>

* docs

Signed-off-by: Miek Gieben <miek@miek.nl>

---------

Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
Miek Gieben
2026-04-21 18:22:02 +10:00
committed by GitHub
parent f44ada06b9
commit 6409a47c71
3 changed files with 37 additions and 0 deletions
+1
View File
@@ -20,6 +20,7 @@ func NewRootCommand() *cobra.Command {
NewListCommand(),
NewUseCommand(),
NewConnectionCommand(),
NewShowCommand(),
)
return cmd
+35
View File
@@ -0,0 +1,35 @@
package context
import (
"fmt"
"github.com/psviderski/uncloud/internal/cli"
"github.com/spf13/cobra"
)
func NewShowCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "show",
Short: "Show current cluster context.",
RunE: func(cmd *cobra.Command, args []string) error {
uncli := cmd.Context().Value("cli").(*cli.CLI)
return show(uncli)
},
}
return cmd
}
func show(uncli *cli.CLI) error {
// discard errors, only show the current context, otherwise nothing
if uncli.Config == nil {
return nil
}
if len(uncli.Config.Contexts) == 0 {
return nil
}
fmt.Println(uncli.Config.CurrentContext)
return nil
}