示例#1
0
文件: tools.go 项目: shoenig/gistit
func readFiles(filenames []string) ([]githubapi.File, error) {
	var files []githubapi.File
	for _, f := range filenames {
		c, e := ioutil.ReadFile(f)
		if e != nil {
			fmt.Println("Error reading file", e)
			os.Exit(1)
		}
		cleaned := githubapi.EscapeNLs(string(c))
		files = append(files, githubapi.NewFile(f, cleaned))
	}
	return files, nil
}
示例#2
0
文件: gistit.go 项目: shoenig/gistit
func main() {
	dummy() // emacs.el does not format correctly without this
	help, desc, fname, args := setFlags()
	if help != false {
		printHelpMessage()
		os.Exit(0)
	}

	if len(args) == 0 {
		all := readStdin()
		gr := githubapi.PushGist(desc, githubapi.NewFile(fname, all))
		fmt.Println(gr.Html_Url)
	} else {
		files, ferr := readFiles(args)
		if ferr != nil {
			fmt.Println("Error reading file", ferr)
			os.Exit(1)
		}
		gr := githubapi.PushMultiGist(desc, files)
		fmt.Println(gr.Html_Url)
	}
}