mirror of
https://github.com/MedzikUser/go-github-selfupdate.git
synced 2024-08-15 03:25:29 +00:00
add detect-latest-release command
This commit is contained in:
parent
07bc4f2027
commit
597627d0b7
7 changed files with 90 additions and 0 deletions
|
@ -13,6 +13,7 @@ build: off
|
|||
test_script:
|
||||
- go build ./selfupdate
|
||||
- go build ./cmd/selfupdate-example
|
||||
- go build ./cmd/detect-latest-release
|
||||
- go test -v -race -coverprofile=coverage.txt ./selfupdate
|
||||
after_test:
|
||||
- "SET PATH=C:\\Python34;C:\\Python34\\Scripts;%PATH%"
|
||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
/selfupdate-example
|
||||
/release
|
||||
/env.sh
|
||||
/detect-latest-release
|
||||
|
|
|
@ -9,6 +9,7 @@ install:
|
|||
script:
|
||||
- go build ./selfupdate/
|
||||
- go build ./cmd/selfupdate-example/
|
||||
- go build ./cmd/detect-latest-release/
|
||||
- go test -v -race -coverprofile=coverage.txt ./selfupdate
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
|
|
|
@ -27,6 +27,10 @@ If newer version than itself is detected, it downloads released binary from GitH
|
|||
- Tested on Linux, macOS and Windows (using Travis CI and AppVeyor)
|
||||
- Many archive and compression formats are supported (zip, gzip, tar)
|
||||
|
||||
And small wrapper CLI is provided:
|
||||
|
||||
- [detect-latest-release](./cmd/detect-latest-release): Detect the latest release of given GitHub repository from command line
|
||||
|
||||
[go-github-selfupdate]: https://github.com/rhysd/go-github-selfupdate
|
||||
[GitHub Releases API]: https://developer.github.com/v3/repos/releases/
|
||||
|
||||
|
|
14
cmd/detect-latest-release/README.md
Normal file
14
cmd/detect-latest-release/README.md
Normal file
|
@ -0,0 +1,14 @@
|
|||
This command line tool is a small wrapper of [`selfupdate.DetectLatest()`](https://godoc.org/github.com/rhysd/go-github-selfupdate/selfupdate#DetectLatest).
|
||||
|
||||
Please install using `go get`.
|
||||
|
||||
```
|
||||
$ go get -u github.com/rhysd/go-github-selfupdate/cmd/detect-latest-release
|
||||
```
|
||||
|
||||
To know the usage, please try the command without any argument.
|
||||
|
||||
```
|
||||
$ detect-latest-release
|
||||
```
|
||||
|
66
cmd/detect-latest-release/main.go
Normal file
66
cmd/detect-latest-release/main.go
Normal file
|
@ -0,0 +1,66 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/rhysd/go-github-selfupdate/selfupdate"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func usage() {
|
||||
fmt.Fprintln(os.Stderr, "Usage: detect-latest-release [flags] {repo}\n\n {repo} must be URL to GitHub repository or in 'owner/name' format.\n\nFlags:\n")
|
||||
flag.PrintDefaults()
|
||||
}
|
||||
|
||||
func main() {
|
||||
asset := flag.Bool("asset", false, "Output URL to asset")
|
||||
notes := flag.Bool("release-notes", false, "Output release notes additionally")
|
||||
url := flag.Bool("url", false, "Output URL for release page")
|
||||
|
||||
flag.Usage = usage
|
||||
flag.Parse()
|
||||
|
||||
if flag.NArg() != 1 {
|
||||
usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
repo := flag.Arg(0)
|
||||
if strings.HasPrefix(repo, "https://") {
|
||||
repo = repo[len("https://"):]
|
||||
}
|
||||
if strings.HasPrefix(repo, "github.com/") {
|
||||
repo = repo[len("github.com/"):]
|
||||
}
|
||||
|
||||
matched, err := regexp.MatchString("[^/]+/[^/]+", repo)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if !matched {
|
||||
usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
latest, found, err := selfupdate.DetectLatest(repo)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if !found {
|
||||
fmt.Println("No release was found")
|
||||
} else {
|
||||
if *asset {
|
||||
fmt.Println(latest.AssetURL)
|
||||
} else if *url {
|
||||
fmt.Println(latest.URL)
|
||||
} else {
|
||||
fmt.Println(latest.Version)
|
||||
if *notes {
|
||||
fmt.Printf("\nRelease Notes:\n%s\n", latest.ReleaseNotes)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -30,5 +30,8 @@ Naming Rules of Git Tags:
|
|||
|
||||
This package is hosted on GitHub:
|
||||
https://github.com/rhysd/go-github-selfupdate
|
||||
|
||||
Small CLI tool as wrapper of this library is available also:
|
||||
https://github.com/rhysd/go-github-selfupdate/cmd/detect-latest-release
|
||||
*/
|
||||
package selfupdate
|
||||
|
|
Loading…
Reference in a new issue