Skip to content

Commit e626163

Browse files
committed
use markdown in output text
1 parent 173770b commit e626163

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

src/pkg/cli/compose.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ func NormalizeServiceName(s string) string {
7070
}
7171

7272
func warnf(format string, args ...interface{}) {
73-
logrus.Warnf(format, args...)
73+
// By default, the logrus StandardLogger writes to os.Stderr
74+
logrus.Warnf(term.MarkDown(term.Stderr, format), args...)
7475
term.HadWarnings = true
7576
}
7677

src/pkg/cli/compose_validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func validateProject(project *compose.Project) error {
2929
warnf("unsupported compose directive: read_only")
3030
}
3131
if svccfg.Restart == "" {
32-
warnf("missing compose directive: restart; assuming 'unless-stopped' (add 'restart' to silence)")
32+
warnf("missing compose directive: `restart`; assuming 'unless-stopped' (add 'restart' to silence)")
3333
} else if svccfg.Restart != "always" && svccfg.Restart != "unless-stopped" {
3434
warnf("unsupported compose directive: restart; assuming 'unless-stopped' (add 'restart' to silence)")
3535
}

src/pkg/quota/quota.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ type Quotas struct {
2020

2121
func (q Quotas) Validate(service *defangv1.Service) error {
2222
if service.Name == "" {
23-
return errors.New("service name is required") // CodeInvalidArgument
23+
return errors.New("service `name:` is required") // CodeInvalidArgument
2424
}
2525

2626
if service.Build != nil {
2727
if service.Build.Context == "" {
28-
return errors.New("build.context is required") // CodeInvalidArgument
28+
return errors.New("build `context:` is required") // CodeInvalidArgument
2929
}
3030
if service.Build.ShmSize > q.ShmSizeMiB || service.Build.ShmSize < 0 {
31-
return fmt.Errorf("build.shm_size exceeds quota (max %v MiB)", q.ShmSizeMiB) // CodeInvalidArgument
31+
return fmt.Errorf("build `shm_size:` exceeds quota (max %v MiB)", q.ShmSizeMiB) // CodeInvalidArgument
3232
}
3333
} else {
3434
if service.Image == "" {
35-
return errors.New("missing image or build") // CodeInvalidArgument
35+
return errors.New("each service must have either `image:` or `build:`") // CodeInvalidArgument
3636
}
3737
}
3838

@@ -91,7 +91,7 @@ func (q Quotas) Validate(service *defangv1.Service) error {
9191
return fmt.Errorf("ingress port requires a CMD healthcheck")
9292
}
9393
default:
94-
return fmt.Errorf("unsupported healthcheck: %v", service.Healthcheck.Test)
94+
return fmt.Errorf("unsupported `healthcheck:` %v", service.Healthcheck.Test)
9595
}
9696
}
9797

src/pkg/term/colorizer.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package term
33
import (
44
"fmt"
55
"os"
6+
"regexp"
67

78
"github.com/muesli/termenv"
89
"golang.org/x/term"
@@ -43,13 +44,27 @@ func ForceColor(color bool) {
4344
}
4445
}
4546

47+
var backticksRegex = regexp.MustCompile("`([^`]+)`")
48+
49+
func markdown(msg string) string {
50+
return backticksRegex.ReplaceAllString(msg, termenv.CSI+"7m$1"+termenv.CSI+"27m")
51+
}
52+
53+
func MarkDown(w *termenv.Output, msg string) string {
54+
if !DoColor(w) {
55+
return msg
56+
}
57+
return markdown(msg)
58+
}
59+
4660
func output(w *termenv.Output, c Color, msg string) (int, error) {
4761
if len(msg) == 0 {
4862
return 0, nil
4963
}
5064
if DoColor(w) {
5165
w.WriteString(termenv.CSI + c.Sequence(false) + "m")
5266
defer w.Reset()
67+
msg = markdown(msg)
5368
}
5469
return w.WriteString(msg)
5570
}

0 commit comments

Comments
 (0)