Created
December 29, 2013 21:09
-
-
Save sleepdeprecation/8174843 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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