Skip to content

Commit

Permalink
fix cli
Browse files Browse the repository at this point in the history
  • Loading branch information
umanggoyald11 committed Jan 18, 2025
1 parent 869fd88 commit 012f586
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
1 change: 1 addition & 0 deletions cmd/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ var createCmd = &cobra.Command{

func init() {
cmd.RootCmd.AddCommand(createCmd)

}
23 changes: 17 additions & 6 deletions cmd/deploy/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"google.golang.org/grpc/status"
"os"
"regexp"

Expand All @@ -15,6 +16,11 @@ import (
"github.com/spf13/cobra"
)

const (
Red = "\033[31m" // Red color for errors
Reset = "\033[0m" // Reset to default
)

var env string
var definitionFile string
var provisioningFile string
Expand Down Expand Up @@ -92,23 +98,20 @@ func deployUsingFiles(ctx context.Context) {
})

if err != nil {
log.Fatal("Failed to deploy service ", err)
handleDeployServiceError(err)
}
}

func deployUsingServiceNameAndVersion(ctx context.Context) {
log.Info("deploying service :", serviceName, ":", serviceVersion, " in env :", env)
err := serviceClient.DeployReleasedService(&ctx, &serviceProto.DeployReleasedServiceRequest{
_ = serviceClient.DeployReleasedService(&ctx, &serviceProto.DeployReleasedServiceRequest{
EnvName: env,
ServiceIdentifier: &serviceProto.ServiceIdentifier{
ServiceName: serviceName,
ServiceVersion: serviceVersion,
},
})

if err != nil {
log.Fatal("Failed to deploy service ", err)
}
}

func deployUsingServiceNameAndLabels(ctx context.Context) {
Expand All @@ -122,7 +125,7 @@ func deployUsingServiceNameAndLabels(ctx context.Context) {
})

if err != nil {
log.Fatal("Failed to deploy service ", err)
handleDeployServiceError(err)
}
}

Expand All @@ -137,3 +140,11 @@ func validateLabels(labels string) error {
}
return nil
}

func handleDeployServiceError(err error) {
if st, ok := status.FromError(err); ok {
log.Fatalf("%s %s: %s %s", Red, st.Message(), Reset)

Check failure on line 146 in cmd/deploy/service.go

View workflow job for this annotation

GitHub Actions / lint

github.com/sirupsen/logrus.Fatalf format %s reads arg #4, but call has 3 args
} else {
log.Fatalf("%s %s: %s %v", Red, err, Reset)

Check failure on line 148 in cmd/deploy/service.go

View workflow job for this annotation

GitHub Actions / lint

github.com/sirupsen/logrus.Fatalf format %v reads arg #4, but call has 3 args
}
}
31 changes: 19 additions & 12 deletions internal/ui/logger.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
package ui

import (
"github.com/dream11/odin/pkg/constant"
"github.com/dream11/odin/pkg/util"
log "github.com/sirupsen/logrus"
)
import log "github.com/sirupsen/logrus"

func init() {
type CustomTextFormatter struct {
BaseFormatter *log.TextFormatter
}

func (f *CustomTextFormatter) Format(entry *log.Entry) ([]byte, error) {
// Return only the log message, ignoring the log level and timestamp
return []byte(entry.Message + "\n"), nil
}

log.SetFormatter(&log.TextFormatter{
ForceColors: true,
DisableColors: false,
TimestampFormat: "2006-01-02 15:04:05", // Custom format
FullTimestamp: true,
func init() {
log.SetFormatter(&CustomTextFormatter{
BaseFormatter: &log.TextFormatter{
ForceColors: true,
DisableColors: false,
DisableTimestamp: true,
DisableLevelTruncation: true,
},
})
level, err := log.ParseLevel(util.GetEnvOrDefault(constant.LogLevelKey, "info"))

level, err := log.ParseLevel("info")
if err != nil {
log.Warning("Invalid log level. Allowed values are: panic, fatal, error, warn, info, debug, trace")
log.SetLevel(log.InfoLevel)
Expand Down

0 comments on commit 012f586

Please sign in to comment.