fix: migrate exit segment correctly

This commit is contained in:
Jan De Dobbeleer 2022-02-02 19:21:16 +01:00 committed by Jan De Dobbeleer
parent 42f9747558
commit a091e5c387
2 changed files with 8 additions and 8 deletions

View file

@ -122,19 +122,19 @@ func (segment *Segment) migrationOne(env environment.Environment) {
segment.migrateColorOverride("version_mismatch_color", "{{ if .Mismatch }}%s{{ end }}") segment.migrateColorOverride("version_mismatch_color", "{{ if .Mismatch }}%s{{ end }}")
} }
case EXIT: case EXIT:
segment.migrateTemplate()
template := segment.Properties.GetString(properties.SegmentTemplate, segment.writer.Template()) 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") alwaysNumeric := properties.Property("always_numeric")
if segment.Properties.GetBool(alwaysNumeric, false) { if segment.Properties.GetBool(alwaysNumeric, false) {
delete(segment.Properties, alwaysNumeric) delete(segment.Properties, alwaysNumeric)
template = strings.ReplaceAll(template, ".Meaning", ".Code") 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.Properties[properties.SegmentTemplate] = template
segment.migrateTemplate()
segment.migrateIconOverride("success_icon", "\uf42e") segment.migrateIconOverride("success_icon", "\uf42e")
segment.migrateIconOverride("error_icon", "\uf00d") segment.migrateIconOverride("error_icon", "\uf00d")
segment.migrateColorOverride("error_color", "{{ if gt .Code 0 }}%s{{ end }}") segment.migrateColorOverride("error_color", "{{ if gt .Code 0 }}%s{{ end }}")

View file

@ -220,8 +220,8 @@ func TestSegmentTemplateMigration(t *testing.T) {
}, },
}, },
{ {
Case: "EXIT - No exit Code with Icon overrides", Case: "EXIT - No exit code",
Expected: " {{ if gt .Code 0 }}FAIL{{ else }}SUCCESS{{ end }} ", Expected: " ",
Type: EXIT, Type: EXIT,
Props: properties.Map{ Props: properties.Map{
"display_exit_code": false, "display_exit_code": false,