feat: make the extension upgrade fancier

This left-pad the extension names during upgrade so they all align
nicely. It makes easier to see what is happening.
This commit is contained in:
nobe4 2025-01-07 12:01:02 +01:00
parent 6c51451660
commit 3b69ea6fbc
No known key found for this signature in database
GPG key ID: 911FE2A36C3403DD
2 changed files with 12 additions and 3 deletions

View file

@ -469,9 +469,18 @@ func (m *Manager) Upgrade(name string, force bool) error {
}
func (m *Manager) upgradeExtensions(exts []*Extension, force bool) error {
var longestExtName = 0
for _, ext := range exts {
l := len(ext.Name())
if len(ext.Name()) > longestExtName {
longestExtName = l
}
}
format := fmt.Sprintf("[%%%ds]: ", longestExtName)
var failed bool
for _, f := range exts {
fmt.Fprintf(m.io.Out, "[%s]: ", f.Name())
fmt.Fprintf(m.io.Out, format, f.Name())
currentVersion := displayExtensionVersion(f, f.CurrentVersion())
err := m.upgradeExtension(f, force)
if err != nil {

View file

@ -256,7 +256,7 @@ func TestManager_UpgradeExtensions(t *testing.T) {
`
[hello]: upgraded from old vers to new vers
[local]: local extensions can not be upgraded
[two]: upgraded from old vers to new vers
[ two]: upgraded from old vers to new vers
`,
), stdout.String())
assert.Equal(t, "", stderr.String())
@ -293,7 +293,7 @@ func TestManager_UpgradeExtensions_DryRun(t *testing.T) {
`
[hello]: would have upgraded from 0 to 1
[local]: local extensions can not be upgraded
[two]: would have upgraded from 2 to 3
[ two]: would have upgraded from 2 to 3
`,
), stdout.String())
assert.Equal(t, "", stderr.String())