This commit is contained in:
rhysd 2017-12-28 17:49:01 +09:00
parent 0c3940241c
commit 11f67e340f
4 changed files with 44 additions and 5 deletions

22
Guardfile Normal file
View File

@ -0,0 +1,22 @@
guard :shell do
watch /^selfupdate\/.+\.go$/ do |m|
puts "#{Time.now}: #{m[0]}"
case m[0]
when /_test\.go$/
parent = File.dirname m[0]
sources = Dir["#{parent}/*.go"].reject{|p| p.end_with? '_test.go'}.join(' ')
system "go test -v -short #{m[0]} #{sources}"
else
system 'go build ./selfupdate/'
end
end
watch /^cmd\/selfupdate-example\/.+\.go$/ do |m|
puts "#{Time.now}: #{m[0]}"
system 'go build ./cmd/selfupdate-example/'
end
watch /^testdata\// do |m|
system "go test -v -short ./selfupdate/"
end
end

View File

@ -10,11 +10,11 @@ import (
const version = "1.2.3"
func selfUpdate() error {
func selfUpdate(slug string) error {
selfupdate.EnableLog()
previous := semver.MustParse(version)
latest, err := selfupdate.UpdateSelf(previous, "rhysd/go-github-selfupdate")
latest, err := selfupdate.UpdateSelf(previous, slug)
if err != nil {
return err
}
@ -29,7 +29,7 @@ func selfUpdate() error {
}
func usage() {
fmt.Fprintln(os.Stderr, "Usage: selfupdate-example [flags]")
fmt.Fprintln(os.Stderr, "Usage: selfupdate-example [flags]\n")
flag.PrintDefaults()
}
@ -37,6 +37,7 @@ func main() {
help := flag.Bool("help", false, "Show this help")
ver := flag.Bool("version", false, "Show version")
update := flag.Bool("selfupdate", false, "Try go-github-selfupdate via GitHub")
slug := flag.String("slug", "rhysd/go-github-selfupdate", "Repository of this command")
flag.Usage = usage
flag.Parse()
@ -52,7 +53,7 @@ func main() {
}
if *update {
if err := selfUpdate(); err != nil {
if err := selfUpdate(*slug); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}

16
selfupdate/e2e_test.go Normal file
View File

@ -0,0 +1,16 @@
package selfupdate
import (
"os/exec"
"testing"
)
func init() {
if err := exec.Command("go", "build", "../cmd/selfupdate-example/main.go").Run(); err != nil {
panic(err)
}
}
func TestRunSelfUpdateExample(t *testing.T) {
t.Fatal("TODO")
}

View File

@ -16,7 +16,7 @@ import (
"strings"
)
func uncompress(src io.ReadCloser, url, cmd string) (io.Reader, error) {
func uncompress(src io.Reader, url, cmd string) (io.Reader, error) {
if strings.HasSuffix(url, ".zip") {
// Zip format requires its file size for uncompressing.
// So we need to read the HTTP response into a buffer at first.