Exemple #1
0
// Create a pastie.
func createPastie(c *cli.Context) {
	fn := strings.TrimSpace(c.Args().First())
	if fn == "" {
		cli.ShowSubcommandHelp(c)
		return
	}

	content, err := ioutil.ReadFile(fn)
	if err != nil {
		fmt.Printf("Can't read '%s'\n", fn)
		return
	}

	pastie, resp, _ := pst.Create(string(content), c.String("lang"), c.Bool("restricted"))

	if resp.StatusCode != http.StatusOK {
		fmt.Println(resp.Status)
	}

	shortURL, err := isgd.Short(pastie)
	if err != nil {
		panic(err)
	}

	fmt.Printf("File: %s\nPastie URL: %s\nShort URL: %s\n",
		fn, pastie, shortURL)

}
Exemple #2
0
// Create a gist.
func createGist(c *cli.Context) {
	fn := strings.TrimSpace(c.Args().First())
	if fn == "" {
		cli.ShowSubcommandHelp(c)
		return
	}
	if hasGithubToken(c) {
		if !com.IsFile(fn) {
			fmt.Printf("'%s' is not a file.\n", fn)
			return
		}

		content, err := ioutil.ReadFile(fn)
		if err != nil {
			fmt.Printf("Can't read '%s'\n", fn)
			return
		}
		_, file := filepath.Split(fn)

		gp := gst.CreateParams{
			FileName:    file,
			Description: c.String("description"),
			Content:     string(content),
			Public:      c.Bool("public"),
		}
		gistURL, resp, _ := gst.Create(c.String(githubToken), gp)

		if resp.StatusCode != http.StatusCreated {
			fmt.Println(resp.Status)
		}

		shortURL, err := isgd.Short(gistURL)
		if err != nil {
			panic(err)
		}

		fmt.Printf("File: %s\nGist URL: %s\nShort URL: %s\n",
			fn, gistURL, shortURL)

	} else {
		fmt.Println("Github Oauth2 Token not found!")
		return
	}
}