Skip to content

Instantly share code, notes, and snippets.

@sleepdeprecation
Created December 29, 2013 21:09
Show Gist options
  • Save sleepdeprecation/8174843 to your computer and use it in GitHub Desktop.
Save sleepdeprecation/8174843 to your computer and use it in GitHub Desktop.
package main
import (
"flag"
"fmt"
//"github.com/MaximeD/gost/conf"
//"github.com/MaximeD/gost/gist"
"./gist"
"./conf"
"os"
)
var baseUrl string = "https://api.github.com/"
// get command line arguments
var gistDescriptionFlag = flag.String("description", "", "Description of the gist")
var gistPrivateFlag = flag.Bool("private", false, "Set gist to private")
var listGistsFlag = flag.String("list", "", "List gists for a user")
func init() {
flag.StringVar(gistDescriptionFlag, "d", "", "Description of the gist")
flag.BoolVar(gistPrivateFlag, "p", false, "Set gist to private")
flag.StringVar(listGistsFlag, "l", "", "List gists for a user")
}
func main() {
flag.Parse()
isPublic := !*gistPrivateFlag
// if nothing was given write message
if (flag.NFlag() == 0) && (len(flag.Args()) == 0) {
fmt.Println("No arguments or files given!")
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
flag.PrintDefaults()
os.Exit(2)
}
if *listGistsFlag != "" {
username := *listGistsFlag
url := baseUrl + "users/" + username + "/gists"
Gist.List(url)
} else {
filesName := flag.Args()
if len(filesName) == 0 {
fmt.Println("No files given!")
os.Exit(2)
}
token, err := Configuration.GetToken()
if err != nil {
fmt.Println("Couldn't get a token!", err)
os.Exit(2)
}
Gist.Post(baseUrl, token, isPublic, filesName, *gistDescriptionFlag)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment