Exemplo n.º 1
0
Arquivo: cli.go Projeto: fd/simplex
func CLI() {
	var (
		opts_spec_str = strings.Replace(opts_spec_tmpl, "{{CMD}}", path.Base(os.Args[0]), -1)
		opts_spec     = options.MustParse(opts_spec_str)
		opts          = opts_spec.MustInterpret(os.Args, os.Environ())
		env           Environment
	)

	if s := opts.Get("addr"); s != "" {
		env.HttpAddr = s
	}

	if s := opts.Get("port"); s != "" {
		env.HttpAddr = ":" + s
	}

	if s := opts.Get("src"); s != "" {
		env.Source = s
	}

	if s := opts.Get("dst"); s != "" {
		env.Destination = s
	}

	switch opts.Command {

	case "server":
		err := Serve(env)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}

	case "generate":
		err := Generate(env)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}

	default:
		opts_spec.PrintUsageAndExit()

	}
}
Exemplo n.º 2
0
	"os"
	"os/signal"
	"runtime"
	"syscall"

	"github.com/fd/heroku-keepalive/api"
	"github.com/fd/heroku-keepalive/pinger"
	"github.com/fd/options"
)

var spec = options.MustParse(`
heroku-keepalive - Keep heroku websites alive.
Usage: heroku-keepalive --api-key=HEROKU_KEY
--
!api-key=  --api-key,HEROKU_KEY   Heroku API key.
port=      --port,PORT   Heroku API key.
--
--
--

`)

func main() {
	runtime.GOMAXPROCS(runtime.NumCPU() * 2)

	opts := spec.MustInterpret(os.Args, os.Environ())
	if len(opts.Args) != 0 {
		spec.PrintUsageAndExit()
	}

	p := pinger.P{ApiKey: opts.Get("api-key")}