47 lines
890 B
Go
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
|
|
}
|