Skip to content

Commit

Permalink
issue with multiple component status output resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
yashjaind11 committed Oct 23, 2024
1 parent cca031a commit 9377f89
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
5 changes: 2 additions & 3 deletions cmd/describe/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package describe
import (
"encoding/json"
"fmt"

serviceBackend "github.com/dream11/odin/internal/service"
comp "github.com/dream11/odin/proto/gen/go/dream11/od/component/v1"
log "github.com/sirupsen/logrus"

"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -47,7 +47,7 @@ func executeDescribeComponentType(cmd *cobra.Command) {
ctx := cmd.Context()
response, err := componentClient.DescribeComponentType(&ctx, &comp.DescribeComponentTypeRequest{
ComponentType: componentName,
Params: params,
Params: params,
})

if err != nil {
Expand All @@ -64,4 +64,3 @@ func writeAsJSONDescribeComponentType(response *comp.DescribeComponentTypeRespon
}
fmt.Println(string(output))
}

4 changes: 2 additions & 2 deletions internal/service/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"context"
"errors"
"fmt"
"github.com/dream11/odin/pkg/util"
"io"

"github.com/briandowns/spinner"
"github.com/dream11/odin/pkg/constant"
"github.com/dream11/odin/pkg/util"
component "github.com/dream11/odin/proto/gen/go/dream11/od/component/v1"
serviceProto "github.com/dream11/odin/proto/gen/go/dream11/od/service/v1"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -46,7 +46,7 @@ func (e *Component) OperateComponent(ctx *context.Context, request *serviceProto
return err
}
if response != nil {
message = util.GenerateResponseMessage(response.GetServiceResponse())
message = util.GenerateResponseMessageComponentSpecific(response.GetServiceResponse(), []string{request.GetComponentName()})
spinnerInstance.Prefix = fmt.Sprintf(" %s ", message)
spinnerInstance.Start()
}
Expand Down
21 changes: 21 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,24 @@ func GenerateResponseMessage(response *v1.ServiceResponse) string {
}
return message
}

// contains checks if a string is present in an array of strings
func contains(str string, arr []string) bool {
for _, item := range arr {
if item == str {
return true
}
}
return false
}

// GenerateResponseMessageComponentSpecific generate response message from ServiceResponse
func GenerateResponseMessageComponentSpecific(response *v1.ServiceResponse, components []string) string {
message := fmt.Sprintf("\n Service %s %s", response.ServiceStatus.ServiceAction, response.ServiceStatus)
for _, compMessage := range response.ComponentsStatus {
if contains(compMessage.ComponentName, components) {
message += fmt.Sprintf("\n Component %s %s %s %s", compMessage.ComponentName, compMessage.ComponentAction, compMessage.ComponentStatus, compMessage.Error)
}
}
return message
}

0 comments on commit 9377f89

Please sign in to comment.