Files
ward/cmd/root.go
James McDonald a0a7932f99
All checks were successful
Release / release (push) Successful in 1m38s
Refactor project layout
2026-04-01 13:16:06 +02:00

47 lines
890 B
Go

package cmd
import (
"fmt"
"os"
"strings"
"github.com/spf13/cobra"
)
// Execute builds the root command and runs it.
func Execute() {
root := newRootCmd()
if err := root.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func newRootCmd() *cobra.Command {
root := &cobra.Command{
Use: "ward",
Short: "Kubernetes credential gateway",
SilenceUsage: true,
SilenceErrors: true,
}
root.AddCommand(newServeCmd())
root.AddCommand(newCredentialCmd())
root.AddCommand(newLoginCmd())
return root
}
// normalizeServer ensures server has an https:// scheme and a port.
// Shared by the credential and login commands.
func normalizeServer(server string) string {
if !strings.Contains(server, "://") {
server = "https://" + server
}
parts := strings.Split(server, ":")
if len(parts) == 2 {
server += ":8443"
}
return server
}