From d79328e3cfa2fda36d2012ca68de84fb72c793eb Mon Sep 17 00:00:00 2001 From: shreyasbhat0 Date: Fri, 1 Dec 2023 14:03:05 +0530 Subject: [PATCH] feat: update interfaces and command builder --- cli/common/command_builder.go | 11 ++++++-- cli/common/command_builder_test.go | 2 +- cli/common/interfaces.go | 15 +++++++---- cli/common/spinner.go | 40 ++++++++++++++++++++++-------- 4 files changed, 50 insertions(+), 18 deletions(-) diff --git a/cli/common/command_builder.go b/cli/common/command_builder.go index 280a83e2..c6571b5d 100644 --- a/cli/common/command_builder.go +++ b/cli/common/command_builder.go @@ -92,9 +92,9 @@ func (dc *diveCommandBuilder) SetLong(long string) CommandBuilder { } // SetRun sets the Run field of the command. -func (dc *diveCommandBuilder) SetRun(run func(cmd *cobra.Command, args []string) error) CommandBuilder { +func (dc *diveCommandBuilder) SetRun(run func(cmd *cobra.Command, args []string)) CommandBuilder { - dc.cmd.RunE = run + dc.cmd.Run = run return dc } @@ -103,3 +103,10 @@ func (dc *diveCommandBuilder) ToggleHelpCommand(enable bool) CommandBuilder { dc.cmd.SetHelpCommand(&cobra.Command{Hidden: enable}) return dc } + +func (dc *diveCommandBuilder) SetRunE(run func(cmd *cobra.Command, args []string) error) CommandBuilder { + + dc.cmd.RunE = run + + return dc +} diff --git a/cli/common/command_builder_test.go b/cli/common/command_builder_test.go index 141e2366..c3857c2f 100644 --- a/cli/common/command_builder_test.go +++ b/cli/common/command_builder_test.go @@ -16,7 +16,7 @@ func TestDiveCommandBuilder(t *testing.T) { builder.SetUse("testCommand"). SetShort("Short description"). SetLong("Long description"). - SetRun(func(cmd *cobra.Command, args []string) error { + SetRunE(func(cmd *cobra.Command, args []string) error { cmd.Println("test function") return nil diff --git a/cli/common/interfaces.go b/cli/common/interfaces.go index fbda6222..9cdc2bab 100644 --- a/cli/common/interfaces.go +++ b/cli/common/interfaces.go @@ -24,10 +24,13 @@ type Logger interface { } type Spinner interface { - SetMessage(message string, color string) + SetSuffixMessage(message, color string) + SetPrefixMessage(message string) SetColor(color string) - Start(message string) - Stop(message string) + Start(color string) + StartWithMessage(message, color string) + Stop() + StopWithMessage(message string) } type Context interface { @@ -37,7 +40,7 @@ type Context interface { CreateEnclave(enclaveName string) GetEnclaves() []string GetSerializedData(response chan *kurtosis_core_rpc_api_bindings.StarlarkRunResponseLine) (string, map[string]string, map[string]bool, error) - InitialiseKurtosisContext() + InitializeKurtosisContext() StopServices() StopService() } @@ -96,7 +99,9 @@ type CommandBuilder interface { SetLong(long string) CommandBuilder // SetRun sets the Run field of the command. - SetRun(run func(cmd *cobra.Command, args []string) error) CommandBuilder + SetRun(run func(cmd *cobra.Command, args []string)) CommandBuilder ToggleHelpCommand(enable bool) CommandBuilder + + SetRunE(run func(cmd *cobra.Command, args []string) error) CommandBuilder } diff --git a/cli/common/spinner.go b/cli/common/spinner.go index 5fd6c68c..91a084d1 100644 --- a/cli/common/spinner.go +++ b/cli/common/spinner.go @@ -13,24 +13,44 @@ type diveSpinner struct { func NewDiveSpinner() *diveSpinner { - spinner := spinner.New(spinner.CharSets[80], 100*time.Millisecond, spinner.WithWriter(os.Stdin)) - - return &diveSpinner{spinner: spinner} + return &diveSpinner{ + spinner: spinner.New(spinner.CharSets[80], 100*time.Millisecond, spinner.WithWriter(os.Stdin)), + } } -func (ds *diveSpinner) SetMessage(message string, color string) { - panic("not implemented") // TODO: Implement +func (ds *diveSpinner) SetSuffixMessage(message, color string) { + ds.spinner.Suffix = message + ds.SetColor(color) +} +func (ds *diveSpinner) SetPrefixMessage(message string) { + ds.spinner.Prefix = message } func (ds *diveSpinner) SetColor(color string) { - panic("not implemented") // TODO: Implement + ds.spinner.Color(color) +} + +func (ds *diveSpinner) Start(color string) { + ds.SetColor(color) + ds.spinner.Start() +} + +func (ds *diveSpinner) StartWithMessage(message, color string) { + + ds.SetSuffixMessage(message, color) + ds.Start(color) +} + +func (ds *diveSpinner) Stop() { + ds.spinner.Stop() } -func (ds *diveSpinner) Start(message string) { - panic("not implemented") // TODO: Implement +func (ds *diveSpinner) StopWithMessage(message string) { + ds.setFinalMessage(message) + ds.Stop() } -func (ds *diveSpinner) Stop(message string) { - panic("not implemented") // TODO: Implement +func (ds *diveSpinner) setFinalMessage(message string) { + ds.spinner.FinalMSG = message }