Commit d923c1b4 authored by Addshore's avatar Addshore 🏄
Browse files

Improve updater output

Provides the user with a better error on failure saying why it
failed.
Doesnt output with log. (so no more timestamps)
Does non 0 exit code on failure

Bug: T285628
Change-Id: Ie8f09806d526b1c5385572e472b27e6faff99167
parent 7207d439
......@@ -18,7 +18,6 @@ package cmd
import (
"fmt"
"log"
"os"
"gerrit.wikimedia.org/r/mediawiki/tools/cli/internal/updater"
......@@ -47,12 +46,12 @@ var updateCmd = &cobra.Command{
canUpdate, nextRelease := updater.CanUpdate(Version, GitSummary, Verbosity >= 2)
if !canUpdate || nextRelease == nil {
log.Println("No update available")
fmt.Println("No update available")
os.Exit(0)
}
log.Println("New update found: " + nextRelease.Version.String())
log.Println(nextRelease.AssetURL)
fmt.Println("New update found: " + nextRelease.Version.String())
fmt.Println(nextRelease.AssetURL)
updatePrompt := promptui.Prompt{
Label: " Do you want to update?",
......@@ -60,7 +59,11 @@ var updateCmd = &cobra.Command{
}
_, err := updatePrompt.Run()
if err == nil {
updater.UpdateTo(*nextRelease, Verbosity >= 2)
updateSuccess, updateMessage := updater.UpdateTo(*nextRelease, Verbosity >= 2)
fmt.Println(updateMessage)
if !updateSuccess {
os.Exit(1)
}
}
},
}
......
......@@ -138,10 +138,7 @@ func UpdateTo(release selfupdate.Release, verboseOutput bool) (success bool, mes
err = selfupdate.UpdateTo(release.AssetURL, cmdPath)
if err != nil {
if(verboseOutput){
log.Println("Binary update failed:", err)
}
return false, "Binary update failed"
return false, "Binary update failed" + err.Error()
}
return true, "Successfully updated to version" + release.Version.String() + "\nRelease note:\n" + release.ReleaseNotes
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment