fix(migrate): correctly migrate exit segment

This commit is contained in:
Jan De Dobbeleer 2022-02-20 15:59:52 +01:00 committed by Jan De Dobbeleer
parent dec5691435
commit 39dfca93c6
2 changed files with 19 additions and 6 deletions

View file

@ -134,16 +134,16 @@ func (segment *Segment) migrationOne(env environment.Environment) {
template = strings.ReplaceAll(template, ".Text", ".Meaning") template = strings.ReplaceAll(template, ".Text", ".Meaning")
segment.Properties[properties.SegmentTemplate] = template segment.Properties[properties.SegmentTemplate] = 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.migrateTemplate()
segment.migrateIconOverride("success_icon", "\uf42e") segment.migrateIconOverride("success_icon", "\uf42e")

View file

@ -221,7 +221,7 @@ func TestSegmentTemplateMigration(t *testing.T) {
}, },
{ {
Case: "EXIT - No exit code", Case: "EXIT - No exit code",
Expected: " ", Expected: " {{ if gt .Code 0 }}FAIL{{ else }}SUCCESS{{ end }} ",
Type: EXIT, Type: EXIT,
Props: properties.Map{ Props: properties.Map{
"display_exit_code": false, "display_exit_code": false,
@ -229,6 +229,19 @@ func TestSegmentTemplateMigration(t *testing.T) {
"error_icon": "FAIL", "error_icon": "FAIL",
}, },
}, },
{
Case: "EXIT - No spaces",
Expected: "{{ if gt .Code 0 }}💩{{ else }}🌵{{ end }}",
Type: EXIT,
Props: properties.Map{
"prefix": "",
"postfix": "",
"display_exit_code": false,
"always_enabled": true,
"success_icon": "🌵",
"error_icon": "💩",
},
},
{ {
Case: "EXIT - Always numeric", Case: "EXIT - Always numeric",
Expected: " {{ if gt .Code 0 }}FAIL {{ .Code }}{{ else }}SUCCESS{{ end }} ", Expected: " {{ if gt .Code 0 }}FAIL {{ .Code }}{{ else }}SUCCESS{{ end }} ",