Skip to content

Commit

Permalink
feat: update interfaces and command builder
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyasbhat0 committed Dec 1, 2023
1 parent be65fea commit d79328e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 18 deletions.
11 changes: 9 additions & 2 deletions cli/common/command_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion cli/common/command_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions cli/common/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
}
Expand Down Expand Up @@ -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
}
40 changes: 30 additions & 10 deletions cli/common/spinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit d79328e

Please sign in to comment.