-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
141 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"github.com/alecthomas/kong" | ||
"github.com/blang/semver" | ||
"github.com/rhysd/go-github-selfupdate/selfupdate" | ||
"os" | ||
) | ||
|
||
type updateFlag string | ||
|
||
func (u updateFlag) Decode(ctx *kong.DecodeContext) error { return nil } | ||
func (u updateFlag) IsBool() bool { return true } | ||
func (u updateFlag) BeforeApply(app *kong.Kong, vars kong.Vars) error { | ||
// parse current version | ||
v, err := semver.Parse(Version) | ||
if err != nil { | ||
fmt.Printf("Failed parsing current build version: %v\n", err) | ||
app.Exit(1) | ||
return nil | ||
} | ||
|
||
// detect latest version | ||
fmt.Println("Checking for the latest version...") | ||
latest, found, err := selfupdate.DetectLatest("l3uddz/plexarr") | ||
if err != nil { | ||
fmt.Printf("Failed determining latest available version: %v\n", err) | ||
app.Exit(1) | ||
return nil | ||
} | ||
|
||
// check version | ||
if !found || latest.Version.LTE(v) { | ||
fmt.Printf("Already using the latest version: %v\n", Version) | ||
app.Exit(0) | ||
return nil | ||
} | ||
|
||
// ask update | ||
fmt.Printf("Do you want to update to the latest version: %v? (y/n): ", latest.Version) | ||
input, err := bufio.NewReader(os.Stdin).ReadString('\n') | ||
if err != nil || (input != "y\n" && input != "n\n") { | ||
fmt.Println("Failed validating input...") | ||
app.Exit(1) | ||
return nil | ||
} else if input == "n\n" { | ||
app.Exit(0) | ||
return nil | ||
} | ||
|
||
// get existing executable path | ||
exe, err := os.Executable() | ||
if err != nil { | ||
fmt.Printf("Failed locating current executable path: %v\n", err) | ||
app.Exit(1) | ||
return nil | ||
} | ||
|
||
if err := selfupdate.UpdateTo(latest.AssetURL, exe); err != nil { | ||
fmt.Printf("Failed updating existing binary to latest release: %v\n", err) | ||
app.Exit(1) | ||
return nil | ||
} | ||
|
||
fmt.Printf("Successfully updated to the latest version: %v\n", latest.Version) | ||
|
||
app.Exit(0) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/alecthomas/kong" | ||
) | ||
|
||
type versionFlag string | ||
|
||
func (v versionFlag) Decode(ctx *kong.DecodeContext) error { return nil } | ||
func (v versionFlag) IsBool() bool { return true } | ||
func (v versionFlag) BeforeApply(app *kong.Kong, vars kong.Vars) error { | ||
fmt.Println(vars["version"]) | ||
app.Exit(0) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters