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")
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")
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")

View file

@ -221,7 +221,7 @@ func TestSegmentTemplateMigration(t *testing.T) {
},
{
Case: "EXIT - No exit code",
Expected: " ",
Expected: " {{ if gt .Code 0 }}FAIL{{ else }}SUCCESS{{ end }} ",
Type: EXIT,
Props: properties.Map{
"display_exit_code": false,
@ -229,6 +229,19 @@ func TestSegmentTemplateMigration(t *testing.T) {
"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",
Expected: " {{ if gt .Code 0 }}FAIL {{ .Code }}{{ else }}SUCCESS{{ end }} ",