func readFromStdin() []byte {
	stdin, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		logrus.Fatalf("reading from stdin failed: %v", err)
	}
	return stdin
}
readFromStdin returns everything in stdin.
package main
import (
	"bytes"
	"context"
	"encoding/json"
	"errors"
	"flag"
	"fmt"
	"io/ioutil"
	"net/http"
	"os"
	"os/signal"
	"strings"
	"syscall"
	"github.com/genuinetools/pkg/cli"
	"github.com/jessfraz/pastebinit/version"
	"github.com/sirupsen/logrus"
)
var (
	baseuri  string
	username string
	password string
	debug bool
)
func main() {
	p := cli.NewProgram()
	p.Name = "pastebinit"
	p.Description = "Command line paste bin"
	p.GitCommit = version.GITCOMMIT
	p.Version = version.VERSION
	p.Commands = []cli.Command{
		&serverCommand{},
	}
	p.FlagSet = flag.NewFlagSet("global", flag.ExitOnError)
	p.FlagSet.StringVar(&baseuri, "b", "https://paste.j3ss.co/", "pastebin base uri")
	p.FlagSet.StringVar(&baseuri, "uri", "https://paste.j3ss.co/", "pastebin base uri")
	p.FlagSet.StringVar(&username, "u", os.Getenv("PASTEBINIT_USERNAME"), "username (or env var PASTEBINIT_USERNAME)")
	p.FlagSet.StringVar(&username, "username", os.Getenv("PASTEBINIT_USERNAME"), "username (or env var PASTEBINIT_USERNAME)")
	p.FlagSet.StringVar(&password, "p", os.Getenv("PASTEBINIT_PASSWORD"), "password (or env var PASTEBINIT_PASSWORD)")
	p.FlagSet.StringVar(&password, "password", os.Getenv("PASTEBINIT_PASSWORD"), "password (or env var PASTEBINIT_PASSWORD)")
	p.FlagSet.BoolVar(&debug, "d", false, "enable debug logging")
	p.FlagSet.BoolVar(&debug, "debug", false, "enable debug logging")
	p.Before = func(ctx context.Context) error {
		signals := make(chan os.Signal)
		signal.Notify(signals, os.Interrupt)
		signal.Notify(signals, syscall.SIGTERM)
		_, cancel := context.WithCancel(ctx)
		go func() {
			for sig := range signals {
				cancel()
				logrus.Infof("Received %s, exiting.", sig.String())
				os.Exit(0)
			}
		}()
		if debug {
			logrus.SetLevel(logrus.DebugLevel)
		}
		if !strings.HasSuffix(baseuri, "/") {
			baseuri += "/"
		}
		if !strings.HasPrefix(baseuri, "http") {
			baseuri = "http://" + baseuri
		}
		if len(username) < 1 {
			return errors.New("username cannot be empty")
		}
		if len(password) < 1 {
			return errors.New("password cannot be empty")
		}
		return nil
	}
	p.Action = func(ctx context.Context, args []string) error {
		var content []byte
		if len(args) == 0 {
			content = readFromStdin()
		} else {
			filename := args[0]
			content = readFromFile(filename)
		}
		pasteURI, err := postPaste(content)
		if err != nil {
			return err
		}
		fmt.Printf("Your paste has been uploaded here:\n%s\nthe raw object is here: %s/raw", pasteURI, pasteURI)
		return nil
	}
	p.Run()
}