Skip to content

Commit

Permalink
updated the spinner for the logging
Browse files Browse the repository at this point in the history
Signed-off-by: Dipankar Das <[email protected]>
  • Loading branch information
dipankardas011 committed Feb 3, 2025
1 parent 336fc65 commit dc81a5f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
20 changes: 9 additions & 11 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/ksctl/ksctl/v2/pkg/handler/cluster/controller"

Check failure on line 24 in cmd/create.go

View workflow job for this annotation

GitHub Actions / linux

github.com/ksctl/ksctl/[email protected]: replacement directory ../ksctl does not exist

Check failure on line 24 in cmd/create.go

View workflow job for this annotation

GitHub Actions / macos

github.com/ksctl/ksctl/[email protected]: replacement directory ../ksctl does not exist
controllerMeta "github.com/ksctl/ksctl/v2/pkg/handler/cluster/metadata"

Check failure on line 25 in cmd/create.go

View workflow job for this annotation

GitHub Actions / linux

github.com/ksctl/ksctl/[email protected]: replacement directory ../ksctl does not exist

Check failure on line 25 in cmd/create.go

View workflow job for this annotation

GitHub Actions / macos

github.com/ksctl/ksctl/[email protected]: replacement directory ../ksctl does not exist
"github.com/ksctl/ksctl/v2/pkg/provider"

Check failure on line 26 in cmd/create.go

View workflow job for this annotation

GitHub Actions / linux

github.com/ksctl/ksctl/[email protected]: replacement directory ../ksctl does not exist

Check failure on line 26 in cmd/create.go

View workflow job for this annotation

GitHub Actions / macos

github.com/ksctl/ksctl/[email protected]: replacement directory ../ksctl does not exist
"github.com/pterm/pterm"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -81,33 +80,32 @@ ksctl create --help
os.Exit(1)
}

ss := cli.GetSpinner()
ss.Start("Fetching the region list")

regions, err := managerClient.ListAllRegions()
if err != nil {
ss.StopWithFailure("Failed to fetch the region list", "Reason", err)
k.l.Error("Failed to sync the metadata", "Reason", err)
os.Exit(1)
}
ss.StopWithSuccess("Fetched the region list")

if v, ok := k.getSelectedRegion(regions); !ok {
os.Exit(1)
} else {
meta.Region = v
}
spinner := pterm.DefaultSpinner
// give me the snake spinnner here
spinner.Sequence = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}
ss, err := spinner.Start("Please wait, fetching the instance types")
if err != nil {
k.l.Error("Failed to start the spinner", "Reason", err)
os.Exit(1)
}
ss = cli.GetSpinner()
ss.Start("Fetching the instance type list")

vms, err := managerClient.ListAllInstances(meta.Region)
if err != nil {
ss.Fail(fmt.Sprintf("Unable to get instance_type list: %v", err))
ss.StopWithFailure("Failed to fetch the instance type list", "Reason", err)
k.l.Error("Failed to sync the metadata", "Reason", err)
os.Exit(1)
}
ss.Success("Fetched the instance type list")
ss.StopWithSuccess("Fetched the instance type list")
if v, ok := k.getSelectedInstanceType(vms); !ok {
os.Exit(1)
} else {
Expand Down
26 changes: 26 additions & 0 deletions pkg/cli/menudriven.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,32 @@ import (
"github.com/pterm/pterm"
)

type Spinner struct {
c pterm.SpinnerPrinter
s *pterm.SpinnerPrinter
}

func GetSpinner() *Spinner {
spinner := pterm.DefaultSpinner
spinner.Sequence = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}

return &Spinner{
c: spinner,
}
}

func (s *Spinner) Start(msg ...any) {
s.s, _ = s.c.Start(msg...)
}

func (s *Spinner) StopWithSuccess(msg ...any) {
s.s.Success(msg...)
}

func (s *Spinner) StopWithFailure(msg ...any) {
s.s.Fail(msg...)
}

func Confirmation(prompt, defaultOption string) (proceed bool, err error) {
x := pterm.DefaultInteractiveConfirm
if len(defaultOption) != 0 {
Expand Down

0 comments on commit dc81a5f

Please sign in to comment.