Skip to content

Commit

Permalink
New Long help message banner
Browse files Browse the repository at this point in the history
Signed-off-by: Dipankar Das <65275144+dipankardas011@users.noreply.github.com>
  • Loading branch information
dipankardas011 committed Aug 18, 2024
1 parent b6c01df commit dc8f10f
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 58 deletions.
16 changes: 8 additions & 8 deletions cli/cmd/createCluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ksctl create --help
`,
Short: "Use to create a cluster",
Aliases: []string{"create"},
Long: "It is used to create cluster with the given name from user",
Long: LongMessage("It is used to create cluster with the given name from user"),
}

var createClusterAzure = &cobra.Command{
Expand All @@ -25,7 +25,7 @@ var createClusterAzure = &cobra.Command{
ksctl create-cluster azure -n demo -r eastus -s store-local --nodeSizeMP Standard_DS2_v2 --noMP 3
`,
Short: "Use to create a AKS cluster in Azure",
Long: "It is used to create cluster with the given name from user",
Long: LongMessage("It is used to create cluster with the given name from user"),
Run: func(cmd *cobra.Command, args []string) {
verbosity, _ := cmd.Flags().GetInt("verbose")
var log types.LoggerFactory = logger.NewLogger(verbosity, os.Stdout)
Expand All @@ -45,7 +45,7 @@ var createClusterAws = &cobra.Command{
ksctl create-cluster aws -n demo -r ap-south-1 -s store-local --nodeSizeMP t2.micro --noMP 3
`,
Short: "Use to create a EKS cluster in Aws",
Long: "It is used to create cluster with the given name from user",
Long: LongMessage("It is used to create cluster with the given name from user"),
Run: func(cmd *cobra.Command, args []string) {
verbosity, _ := cmd.Flags().GetInt("verbose")
var log types.LoggerFactory = logger.NewLogger(verbosity, os.Stdout)
Expand All @@ -65,7 +65,7 @@ var createClusterCivo = &cobra.Command{
ksctl create-cluster civo --name demo --region LON1 --storage store-local --nodeSizeMP g4s.kube.small --noMP 3
`,
Short: "Use to create a Civo managed k3s cluster",
Long: "It is used to create cluster with the given name from user",
Long: LongMessage("It is used to create cluster with the given name from user"),
Run: func(cmd *cobra.Command, args []string) {
verbosity, _ := cmd.Flags().GetInt("verbose")
var log types.LoggerFactory = logger.NewLogger(verbosity, os.Stdout)
Expand All @@ -85,7 +85,7 @@ var createClusterLocal = &cobra.Command{
ksctl create-cluster local --name demo --storage store-local --noMP 3
`,
Short: "Use to create a kind cluster",
Long: "It is used to create cluster with the given name from user",
Long: LongMessage("It is used to create cluster with the given name from user"),
Run: func(cmd *cobra.Command, args []string) {
verbosity, _ := cmd.Flags().GetInt("verbose")
var log types.LoggerFactory = logger.NewLogger(verbosity, os.Stdout)
Expand All @@ -105,7 +105,7 @@ var createClusterHAAws = &cobra.Command{
ksctl create-cluster ha-aws -n demo -r us-east-1 --bootstrap k3s -s store-local --nodeSizeCP t2.medium --nodeSizeWP t2.medium --nodeSizeLB t2.micro --nodeSizeDS t2.small --noWP 1 --noCP 3 --noDS 3
`,
Short: "Use to create a self-managed Highly Available cluster on AWS",
Long: "It is used to create cluster with the given name from user.",
Long: LongMessage("It is used to create cluster with the given name from user."),
Run: func(cmd *cobra.Command, args []string) {
verbosity, _ := cmd.Flags().GetInt("verbose")
var log types.LoggerFactory = logger.NewLogger(verbosity, os.Stdout)
Expand All @@ -126,7 +126,7 @@ ksctl create-cluster ha-civo --name demo --region LON1 --bootstrap k3s --storage
ksctl create-cluster ha-civo --name demo --region LON1 --bootstrap kubeadm --storage store-local --nodeSizeCP g3.medium --nodeSizeWP g3.large --nodeSizeLB g3.small --nodeSizeDS g3.small --noWP 1 --noCP 3 --noDS 3
`,
Short: "Use to create a self-managed Highly Available cluster on Civo",
Long: "It is used to create cluster with the given name from user",
Long: LongMessage("It is used to create cluster with the given name from user"),
Run: func(cmd *cobra.Command, args []string) {
verbosity, _ := cmd.Flags().GetInt("verbose")
var log types.LoggerFactory = logger.NewLogger(verbosity, os.Stdout)
Expand All @@ -147,7 +147,7 @@ ksctl create-cluster ha-azure --name demo --region eastus --bootstrap k3s --stor
ksctl create-cluster ha-azure --name demo --region eastus --bootstrap kubeadm --storage store-local --nodeSizeCP Standard_F2s --nodeSizeWP Standard_F4s --nodeSizeLB Standard_F2s --nodeSizeDS Standard_F2s --noWP 1 --noCP 3 --noDS 3
`,
Short: "Use to create a self-managed Highly-Available cluster on Azure",
Long: "It is used to create cluster with the given name from user",
Long: LongMessage("It is used to create cluster with the given name from user"),
Run: func(cmd *cobra.Command, args []string) {
verbosity, _ := cmd.Flags().GetInt("verbose")
var log types.LoggerFactory = logger.NewLogger(verbosity, os.Stdout)
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
var credCmd = &cobra.Command{
Use: "cred",
Short: "Login to your Cloud-provider Credentials",
Long: "login to your cloud provider credentials",
Long: LongMessage("login to your cloud provider credentials"),
Run: func(cmd *cobra.Command, args []string) {
verbosity, _ := cmd.Flags().GetInt("verbose")
var log types.LoggerFactory = logger.NewLogger(verbosity, os.Stdout)
Expand Down
16 changes: 8 additions & 8 deletions cli/cmd/deleteCluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ksctl delete --help
`,
Short: "Use to delete a cluster",
Aliases: []string{"delete"},
Long: "It is used to delete cluster of given provider",
Long: LongMessage("It is used to delete cluster of given provider"),
}

var deleteClusterLocal = &cobra.Command{
Expand All @@ -25,7 +25,7 @@ var deleteClusterLocal = &cobra.Command{
ksctl delete local --name demo --storage store-local
`,
Short: "Use to delete a kind cluster",
Long: "It is used to delete cluster of given provider",
Long: LongMessage("It is used to delete cluster of given provider"),
Run: func(cmd *cobra.Command, args []string) {
verbosity, _ := cmd.Flags().GetInt("verbose")
var log types.LoggerFactory = logger.NewLogger(verbosity, os.Stdout)
Expand All @@ -45,7 +45,7 @@ var deleteClusterAzure = &cobra.Command{
ksctl delete azure --name demo --region eastus --storage store-local
`,
Short: "Use to deletes a AKS cluster",
Long: "It is used to delete cluster of given provider",
Long: LongMessage("It is used to delete cluster of given provider"),
Run: func(cmd *cobra.Command, args []string) {
verbosity, _ := cmd.Flags().GetInt("verbose")
var log types.LoggerFactory = logger.NewLogger(verbosity, os.Stdout)
Expand All @@ -65,7 +65,7 @@ var deleteClusterAws = &cobra.Command{
ksctl delete aws --name demo --region ap-south-1 --storage store-local
`,
Short: "Use to deletes a EKS cluster",
Long: "It is used to delete cluster of given provider",
Long: LongMessage("It is used to delete cluster of given provider"),
Run: func(cmd *cobra.Command, args []string) {
verbosity, _ := cmd.Flags().GetInt("verbose")
var log types.LoggerFactory = logger.NewLogger(verbosity, os.Stdout)
Expand All @@ -85,7 +85,7 @@ var deleteClusterCivo = &cobra.Command{
ksctl delete civo --name demo --region LON1 --storage store-local
`,
Short: "Use to delete a Civo managed k3s cluster",
Long: "It is used to delete cluster of given provider",
Long: LongMessage("It is used to delete cluster of given provider"),
Run: func(cmd *cobra.Command, args []string) {
verbosity, _ := cmd.Flags().GetInt("verbose")
var log types.LoggerFactory = logger.NewLogger(verbosity, os.Stdout)
Expand All @@ -105,7 +105,7 @@ var deleteClusterHAAws = &cobra.Command{
ksctl delete ha-aws --name demo --region us-east-1 --storage store-local
`,
Short: "Use to delete a self-managed Highly Available cluster on AWS",
Long: "It is used to delete cluster of given provider",
Long: LongMessage("It is used to delete cluster of given provider"),
Run: func(cmd *cobra.Command, args []string) {
verbosity, _ := cmd.Flags().GetInt("verbose")
var log types.LoggerFactory = logger.NewLogger(verbosity, os.Stdout)
Expand All @@ -125,7 +125,7 @@ var deleteClusterHAAzure = &cobra.Command{
ksctl delete ha-azure --name demo --region eastus --storage store-local
`,
Short: "Use to delete a self-managed Highly Available cluster on Azure",
Long: "It is used to delete cluster of given provider",
Long: LongMessage("It is used to delete cluster of given provider"),
Run: func(cmd *cobra.Command, args []string) {
verbosity, _ := cmd.Flags().GetInt("verbose")
var log types.LoggerFactory = logger.NewLogger(verbosity, os.Stdout)
Expand All @@ -145,7 +145,7 @@ var deleteClusterHACivo = &cobra.Command{
ksctl delete ha-civo --name demo --region LON1 --storage store-local
`,
Short: "Use to delete a self-managed Highly Available cluster on Civo",
Long: "It is used to delete cluster of given provider",
Long: LongMessage("It is used to delete cluster of given provider"),
Run: func(cmd *cobra.Command, args []string) {
verbosity, _ := cmd.Flags().GetInt("verbose")
var log types.LoggerFactory = logger.NewLogger(verbosity, os.Stdout)
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/getCluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ var getClusterCmd = &cobra.Command{
ksctl get --provider all --storage store-local
`,
Short: "Use to get clusters",
Long: `It is used to view clusters. For example:
Long: LongMessage(`It is used to view clusters. For example:
ksctl get-clusters `,
ksctl get-clusters `),
Run: func(cmd *cobra.Command, args []string) {
verbosity, _ := cmd.Flags().GetInt("verbose")
var log types.LoggerFactory = logger.NewLogger(verbosity, os.Stdout)
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/infoCluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ksctl info --provider azure --name demo --region eastus --storage store-local
ksctl info -p ha-azure -n ha-demo-kubeadm -r eastus -s store-local --verbose -1
`,
Short: "Use to info cluster",
Long: `It is used to detailed data for a given cluster`,
Long: LongMessage(`It is used to detailed data for a given cluster`),
Run: func(cmd *cobra.Command, args []string) {
verbosity, _ := cmd.Flags().GetInt("verbose")
var log types.LoggerFactory = logger.NewLogger(verbosity, os.Stdout)
Expand Down
14 changes: 1 addition & 13 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,7 @@ var (
var RootCmd = &cobra.Command{
Use: "ksctl",
Short: "CLI tool for managing multiple K8s clusters",
Long: `
_ _ _
| | | | | |
| | _____ ___| |_| |
| |/ / __|/ __| __| |
| <\__ \ (__| |_| |
|_|\_\___/\___|\__|_|
CLI tool which can manage multiple K8s clusters
from local clusters to cloud provider specific clusters.`,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) {},
Long: LongMessage("CLI tool which can manage multiple K8s clusters from local clusters to cloud provider specific clusters."),
}

func Execute() {
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/switchCluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ksctl switch-context -s external-store-mongodb -p civo -n <clustername> -r <regi
`,
Aliases: []string{"switch", "access"},
Short: "Use to switch between clusters",
Long: "It is used to switch cluster with the given ClusterName from user.",
Long: LongMessage("It is used to switch cluster with the given ClusterName from user."),
Run: func(cmd *cobra.Command, args []string) {
verbosity, _ := cmd.Flags().GetInt("verbose")
var log types.LoggerFactory = logger.NewLogger(verbosity, os.Stdout)
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func update(version string) error {
var selfUpdate = &cobra.Command{
Use: "self-update",
Short: "update the ksctl cli",
Long: "setups up update for ksctl cli",
Long: LongMessage("to self-update ksctl cli"),
Run: func(cmd *cobra.Command, args []string) {

if Version == "dev" {
Expand Down
27 changes: 27 additions & 0 deletions cli/cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,38 @@ import (
"os"
"strings"

"github.com/fatih/color"
"github.com/ksctl/ksctl/pkg/controllers"
"github.com/ksctl/ksctl/pkg/helpers/consts"
"github.com/ksctl/ksctl/pkg/types"
)

func newLogo() string {
x := strings.Split(v2_0Ksctl, "\n")

y := []string{}

colorCode := map[int]func(str string) string{
0: func(str string) string { return color.New(color.BgHiMagenta).Add(color.FgHiBlack).SprintFunc()(str) },
1: func(str string) string { return color.New(color.BgHiBlue).Add(color.FgHiBlack).SprintFunc()(str) },
2: func(str string) string { return color.New(color.BgHiCyan).Add(color.FgHiBlack).SprintFunc()(str) },
3: func(str string) string { return color.New(color.BgHiGreen).Add(color.FgHiBlack).SprintFunc()(str) },
4: func(str string) string { return color.New(color.BgHiYellow).Add(color.FgHiBlack).SprintFunc()(str) },
5: func(str string) string { return color.New(color.BgHiRed).Add(color.FgHiBlack).SprintFunc()(str) },
}

for i, _x := range x {
if _y, ok := colorCode[i]; ok {
y = append(y, _y(_x))
}
}
return strings.Join(y, "\n")
}

func LongMessage(message string) string {
return fmt.Sprintf("%s\n\n%s", newLogo(), color.New(color.BgHiYellow).Add(color.FgBlack).SprintFunc()(message))
}

func createManaged(ctx context.Context, log types.LoggerFactory, approval bool) {
cli.Client.Metadata.ManagedNodeType = nodeSizeMP
cli.Client.Metadata.NoMP = noMP
Expand Down
24 changes: 1 addition & 23 deletions cli/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"fmt"
"strings"

"github.com/fatih/color"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -41,28 +40,7 @@ var versionCmd = &cobra.Command{

color.HiGreen(v0_1Ksctl)

x := strings.Split(v2_0Ksctl, "\n")

y := []string{}

colorCode := map[int]func(str string) string{
0: func(str string) string { return color.New(color.BgHiMagenta).Add(color.FgHiBlack).SprintFunc()(str) },
1: func(str string) string { return color.New(color.BgHiBlue).Add(color.FgHiBlack).SprintFunc()(str) },
2: func(str string) string { return color.New(color.BgHiCyan).Add(color.FgHiBlack).SprintFunc()(str) },
3: func(str string) string { return color.New(color.BgHiGreen).Add(color.FgHiBlack).SprintFunc()(str) },
4: func(str string) string { return color.New(color.BgHiYellow).Add(color.FgHiBlack).SprintFunc()(str) },
5: func(str string) string { return color.New(color.BgHiRed).Add(color.FgHiBlack).SprintFunc()(str) },
}

for i, _x := range x {
fmt.Println(i, _x)
if _y, ok := colorCode[i]; ok {
y = append(y, _y(_x))
} else {
fmt.Println("Not found", i)
}
}
fmt.Println(strings.Join(y, "\n"))
fmt.Println(newLogo())

fmt.Println("Version:", Version)
fmt.Println("BuildDate:", BuildDate)
Expand Down

0 comments on commit dc8f10f

Please sign in to comment.