Skip to content

Commit aac44d1

Browse files
authored
Introduce FinishWithType() method for Logger (#17)
* Introduce FinishWithType() method for Logger * .golangci.yml: copy Cirrus CLI's config * .golangci.yml: disable ifshort linter * Use fast-forward emoji for skipped status
1 parent 6ae24ba commit aac44d1

File tree

6 files changed

+139
-22
lines changed

6 files changed

+139
-22
lines changed

.golangci.yml

+90-10
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,58 @@ linters-settings:
99
default-signifies-exhaustive: true
1010

1111
linters:
12-
# Selecting all available presets effectively enables all linters.
13-
presets:
14-
- bugs
15-
- complexity
16-
- format
17-
- performance
18-
- style
19-
- unused
12+
enable:
13+
- asciicheck
14+
- bodyclose
15+
- deadcode
16+
- depguard
17+
- dogsled
18+
- dupl
19+
- errcheck
20+
- exhaustive
21+
- exportloopref
22+
- gochecknoinits
23+
- gocognit
24+
- goconst
25+
- gocritic
26+
- gocyclo
27+
- godot
28+
- godox
29+
- goerr113
30+
- gofmt
31+
- goheader
32+
- golint
33+
- gomodguard
34+
- goprintffuncname
35+
- gosec
36+
- gosimple
37+
- govet
38+
- ineffassign
39+
- interfacer
40+
- lll
41+
- makezero
42+
- misspell
43+
- nakedret
44+
- nestif
45+
- noctx
46+
- nolintlint
47+
- predeclared
48+
- rowserrcheck
49+
- scopelint
50+
- sqlclosecheck
51+
- staticcheck
52+
- structcheck
53+
- stylecheck
54+
- testpackage
55+
- tparallel
56+
- typecheck
57+
- unconvert
58+
- unparam
59+
- unused
60+
- varcheck
61+
- whitespace
2062

2163
disable:
22-
- exhaustivestruct
2364
# Messages like "struct of size 104 bytes could be of size 96 bytes" from a package
2465
# that was last updated 2 years ago[1] are barely helpful.
2566
#
@@ -35,15 +76,54 @@ linters:
3576

3677
# New linters that require a lot of codebase churn and noise, but perhaps we can enable them in the future.
3778
- nlreturn
79+
- wrapcheck
80+
- errorlint
81+
82+
# Unfortunately, we use globals due to how spf13/cobra works.
83+
- gochecknoglobals
84+
85+
# That's fine that some Proto objects don't have all fields initialized
86+
- exhaustivestruct
3887

3988
# Style linters that are total nuts.
4089
- wsl
4190
- gofumpt
4291
- goimports
4392
- funlen
4493

45-
# That's fine that some Proto objects don't have all fields initialized
94+
# This conflicts with the Protocol Buffers Version 3 design,
95+
# which is largely based on default values for struct fields.
4696
- exhaustivestruct
97+
98+
# Enough parallelism for now.
99+
- paralleltest
100+
101+
# Ill-based assumptions about identifiers like fmt.Println without taking context into account.
102+
- forbidigo
103+
104+
# Advantages of using t.Helper() are too small to waste developer's cognitive stamina on it.
105+
- thelper
106+
107+
# Too restrictive defaults, plus there's already a gocyclo linter in place.
108+
- cyclop
109+
110+
# Gives false positives for textbook examples[1][2]
111+
# [1]: https://github.com/charithe/durationcheck/issues/7
112+
# [2]: https://golang.org/pkg/time/ (see "To convert an integer number of units to a Duration, multiply:")
113+
- durationcheck
114+
115+
# No way to disable the "exported" check for the whole project[1]
116+
# [1]: https://github.com/mgechev/revive/issues/244#issuecomment-560512162
117+
- revive
118+
119+
# Unfortunately too much false-positives, e.g. for a 0700 umask or number 10 when using strconv.FormatInt()
120+
- gomnd
121+
122+
# Pretty useless linter: there are clearly cases where declaring a variable makes the code more readable,
123+
# yet the only way to weed these cases out is to decrease the "max-decl-chars" option from 30 to some other
124+
# arbitrary value, which makes little sense.
125+
- ifshort
126+
47127
issues:
48128
# Don't hide multiple issues that belong to one class since GitHub annotations can handle them all nicely.
49129
max-issues-per-linter: 0

log_entry.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ func (entry *LogScopeStarted) GetScopes() []string {
3232
}
3333

3434
type LogScopeFinished struct {
35-
scopes []string
36-
success bool
35+
scopes []string
36+
finishType FinishType
3737
}
3838

39-
func NewLogScopeFinished(success bool, scopes ...string) *LogScopeFinished {
39+
func NewLogScopeFinished(finishType FinishType, scopes ...string) *LogScopeFinished {
4040
return &LogScopeFinished{
41-
scopes: scopes,
42-
success: success,
41+
scopes: scopes,
42+
finishType: finishType,
4343
}
4444
}
4545

46-
func (entry *LogScopeFinished) Success() bool {
47-
return entry.success
46+
func (entry *LogScopeFinished) FinishType() FinishType {
47+
return entry.finishType
4848
}
4949

5050
func (entry *LogScopeFinished) GetScopes() []string {

logger.go

+21-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ type Logger struct {
1818
entriesChannel chan *genericLogEntry
1919
}
2020

21+
type FinishType int
22+
23+
const (
24+
FinishTypeSucceeded FinishType = iota
25+
FinishTypeFailed
26+
FinishTypeSkipped
27+
)
28+
2129
func NewLogger(level LogLevel, renderer LogRendered) *Logger {
2230
logger := &Logger{
2331
level: level,
@@ -83,8 +91,20 @@ func (logger *Logger) Logf(level LogLevel, format string, args ...interface{}) {
8391
}
8492

8593
func (logger *Logger) Finish(success bool) {
94+
var finishType FinishType
95+
96+
if success {
97+
finishType = FinishTypeSucceeded
98+
} else {
99+
finishType = FinishTypeFailed
100+
}
101+
102+
logger.FinishWithType(finishType)
103+
}
104+
105+
func (logger *Logger) FinishWithType(finishType FinishType) {
86106
logger.entriesChannel <- &genericLogEntry{
87-
LogFinished: NewLogScopeFinished(success, logger.scopes...),
107+
LogFinished: NewLogScopeFinished(finishType, logger.scopes...),
88108
}
89109
}
90110

renderers/config/interactive_config.go

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type InteractiveRendererConfig struct {
1313
ProgressIndicatorCycleDuration time.Duration
1414
SuccessStatus string
1515
FailureStatus string
16+
SkippedStatus string
1617
DescriptionLinesWhenFailed int
1718
}
1819

@@ -34,6 +35,7 @@ func NewDefaultEmojiRenderingConfig() *InteractiveRendererConfig {
3435
ProgressIndicatorCycleDuration: time.Second,
3536
SuccessStatus: "✅",
3637
FailureStatus: "❌",
38+
SkippedStatus: "⏩",
3739
DescriptionLinesWhenFailed: 100,
3840
}
3941
}
@@ -49,6 +51,7 @@ func NewDefaultSymbolsOnlyRenderingConfig() *InteractiveRendererConfig {
4951
ProgressIndicatorCycleDuration: time.Second,
5052
SuccessStatus: "+",
5153
FailureStatus: "-",
54+
SkippedStatus: "!",
5255
DescriptionLinesWhenFailed: 100,
5356
}
5457
}

renderers/interactive.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,23 @@ func (r *InteractiveRenderer) RenderScopeStarted(entry *echelon.LogScopeStarted)
5151

5252
func (r *InteractiveRenderer) RenderScopeFinished(entry *echelon.LogScopeFinished) {
5353
n := findScopedNode(entry.GetScopes(), r)
54-
if entry.Success() {
54+
55+
switch entry.FinishType() {
56+
case echelon.FinishTypeSucceeded:
5557
if n != r.rootNode {
5658
n.ClearAllChildren()
5759
n.ClearDescription()
5860
}
5961
n.CompleteWithColor(r.config.SuccessStatus, r.config.Colors.SuccessColor)
60-
} else {
62+
case echelon.FinishTypeFailed:
6163
n.SetVisibleDescriptionLines(r.config.DescriptionLinesWhenFailed)
6264
n.CompleteWithColor(r.config.FailureStatus, r.config.Colors.FailureColor)
65+
case echelon.FinishTypeSkipped:
66+
if n != r.rootNode {
67+
n.ClearAllChildren()
68+
n.ClearDescription()
69+
}
70+
n.CompleteWithColor(r.config.SkippedStatus, r.config.Colors.NeutralColor)
6371
}
6472
}
6573

renderers/simple.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,20 @@ func (r SimpleRenderer) RenderScopeFinished(entry *echelon.LogScopeFinished) {
6060
duration := now.Sub(startTime)
6161
formatedDuration := utils.FormatDuration(duration, true)
6262
lastScope := scopes[level-1]
63-
if entry.Success() {
63+
64+
switch entry.FinishType() {
65+
case echelon.FinishTypeSucceeded:
6466
message := fmt.Sprintf("%s succeeded in %s!", quotedIfNeeded(lastScope), formatedDuration)
6567
coloredMessage := terminal.GetColoredText(r.colors.SuccessColor, message)
6668
r.renderEntry(coloredMessage)
67-
} else {
69+
case echelon.FinishTypeFailed:
6870
message := fmt.Sprintf("%s failed in %s!", quotedIfNeeded(lastScope), formatedDuration)
6971
coloredMessage := terminal.GetColoredText(r.colors.NeutralColor, message)
7072
r.renderEntry(coloredMessage)
73+
case echelon.FinishTypeSkipped:
74+
message := fmt.Sprintf("%s skipped in %s!", quotedIfNeeded(lastScope), formatedDuration)
75+
coloredMessage := terminal.GetColoredText(r.colors.NeutralColor, message)
76+
r.renderEntry(coloredMessage)
7177
}
7278
}
7379

0 commit comments

Comments
 (0)