Esempio n. 1
0
func main() {
	owner, repo := "geofffranks", "spruce"
	if len(os.Args) < 1 || len(os.Args) > 4 {
		usage()
	}
	fmt.Printf("os.Args: %v\n", os.Args)
	switch os.Args[1] {
	case "list":
	case "download":
	default:
		usage()
	}
	if len(os.Args) > 2 {
		owner = os.Args[2]
	}
	if len(os.Args) > 3 {
		repo = os.Args[3]
	}

	r, err := github.Releases(owner, repo)
	if err != nil {
		fmt.Printf("error: %s\n", err)
		return
	}
	versions := github.LatestFrom("1.0.2", r)

	switch os.Args[1] {
	case "list":
		for _, v := range versions {
			fmt.Printf("%s\n", v)
		}

	case "download":
		for _, v := range versions {
			fmt.Printf("downloading spruce v%s, to spruce-%s\n", v, v)
			f, err := os.Create(fmt.Sprintf("spruce-%s", v))
			if err != nil {
				fmt.Printf("error: %s\n", err)
				continue
			}
			github.Download(owner, repo, v, f)
			f.Close()
		}

	default:
		usage()
	}
}
Esempio n. 2
0
func GetSpruces() ([]string, error) {
	r, err := github.Releases("geofffranks", "spruce")
	if err != nil {
		return nil, fmt.Errorf("github api: %s", err)
	}
	l := github.LatestFrom("1.0.2", r)
	for _, v := range l {
		f, err := os.Create(fmt.Sprintf("/tmp/spruce-%s", v))
		if err != nil {
			return nil, fmt.Errorf("failed to save spruce v%s: %s", v, err)
		}
		log.Printf("downloading spruce v%s", v)
		err = github.Download("geofffranks", "spruce", v, f)
		if err != nil {
			return nil, fmt.Errorf("failed to save spruce v%s: %s", v, err)
		}
		f.Chmod(0755)
		f.Close()
	}
	return l, nil
}