Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/operate comp status #263

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading