Adding upstream version 1.2.3.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
3a3aa427d7
commit
e7ed09875d
58 changed files with 3068 additions and 0 deletions
20
cmd/detect-latest-release/README.md
Normal file
20
cmd/detect-latest-release/README.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
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
|
||||
```
|
||||
|
||||
For example, following shows the latest version of [github-clone-all](https://github.com/rhysd/github-clone-all).
|
||||
|
||||
```
|
||||
$ detect-latest-release rhysd/github-clone-all
|
||||
```
|
||||
|
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue