From a091e5c387b9ae9496571e55f5998d03c7623f37 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Wed, 2 Feb 2022 19:21:16 +0100 Subject: [PATCH] fix: migrate exit segment correctly --- src/engine/migrations.go | 12 ++++++------ src/engine/migrations_test.go | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/engine/migrations.go b/src/engine/migrations.go index 2ec8fb78..09f97c93 100644 --- a/src/engine/migrations.go +++ b/src/engine/migrations.go @@ -122,19 +122,19 @@ func (segment *Segment) migrationOne(env environment.Environment) { segment.migrateColorOverride("version_mismatch_color", "{{ if .Mismatch }}%s{{ end }}") } case EXIT: - segment.migrateTemplate() template := segment.Properties.GetString(properties.SegmentTemplate, segment.writer.Template()) - displayExitCode := properties.Property("display_exit_code") - if !segment.Properties.GetBool(displayExitCode, true) { - delete(segment.Properties, displayExitCode) - template = strings.ReplaceAll(template, " {{ .Meaning }}", "") - } alwaysNumeric := properties.Property("always_numeric") if segment.Properties.GetBool(alwaysNumeric, false) { delete(segment.Properties, alwaysNumeric) template = strings.ReplaceAll(template, ".Meaning", ".Code") } + displayExitCode := properties.Property("display_exit_code") + if !segment.Properties.GetBool(displayExitCode, true) { + delete(segment.Properties, displayExitCode) + template = " " + } segment.Properties[properties.SegmentTemplate] = template + segment.migrateTemplate() segment.migrateIconOverride("success_icon", "\uf42e") segment.migrateIconOverride("error_icon", "\uf00d") segment.migrateColorOverride("error_color", "{{ if gt .Code 0 }}%s{{ end }}") diff --git a/src/engine/migrations_test.go b/src/engine/migrations_test.go index 4617201f..44d4a574 100644 --- a/src/engine/migrations_test.go +++ b/src/engine/migrations_test.go @@ -220,8 +220,8 @@ func TestSegmentTemplateMigration(t *testing.T) { }, }, { - Case: "EXIT - No exit Code with Icon overrides", - Expected: " {{ if gt .Code 0 }}FAIL{{ else }}SUCCESS{{ end }} ", + Case: "EXIT - No exit code", + Expected: " ", Type: EXIT, Props: properties.Map{ "display_exit_code": false,