Example #1
0
func cliSetup() *cliOptions {

	options := newCliOptions()

	var httpVerb = goopt.StringWithLabel([]string{"-X", "--command"}, options.httpVerb,
		"COMMAND", fmt.Sprintf("HTTP verb for request: %s", HttpVerbs))
	var httpHeaders = goopt.Strings([]string{"-H", "--header"},
		"KEY:VALUE", "Custom HTTP Headers to be sent with request (can pass multiple times)")
	var postData = goopt.StringWithLabel([]string{"-d", "--data"}, options.postData,
		"DATA", "HTTP Data for POST")
	var timeOut = goopt.IntWithLabel([]string{"-t", "--timeout"}, options.timeout,
		"TIMEOUT", "Timeout in seconds for request")
	var shouldRedirect = goopt.Flag([]string{"-r", "--redirect"}, []string{}, "Follow redirects", "")
	var isVerbose = goopt.Flag([]string{"-v", "--verbose"}, []string{}, "Verbose output", "")
	var hasColor = goopt.Flag([]string{"-c", "--color"}, []string{}, "Colored output", "")
	var isInsecureSSL = goopt.Flag([]string{"-k", "--insecure"}, []string{}, "Allow insecure https connections", "")

	goopt.Summary = "Golang based http client program"
	goopt.Parse(nil)

	options.httpVerb = *httpVerb
	options.httpHeaders = *httpHeaders
	options.postData = *postData
	options.timeout = *timeOut
	options.verbose = *isVerbose
	options.redirect = *shouldRedirect
	options.color = *hasColor
	options.sslInsecure = *isInsecureSSL
	options.arguments = goopt.Args

	exitWithMessageIfNonZero(validateOptions(options))
	exitWithMessageIfNonZero(validateArguments(options))

	return options
}
Example #2
0
	"path/filepath"
	"regexp"
)

var (
	Author  = "Alexander Solovyov"
	Version = "0.4.3"
	Summary = "gr [OPTS] string-to-search\n"

	byteNewLine []byte = []byte("\n")

	ignoreCase = goopt.Flag([]string{"-i", "--ignore-case"}, []string{},
		"ignore pattern case", "")
	onlyName = goopt.Flag([]string{"-n", "--filename"}, []string{},
		"print only filenames", "")
	ignoreFiles = goopt.Strings([]string{"-x", "--exclude"}, "RE",
		"exclude files that match the regexp from search")
	singleline = goopt.Flag([]string{"-s", "--singleline"}, []string{},
		"match on a single line (^/$ will be beginning/end of line)", "")
	plaintext = goopt.Flag([]string{"-p", "--plain"}, []string{},
		"search plain text", "")
	replace = goopt.String([]string{"-r", "--replace"}, "",
		"replace found substrings with this string")
	force = goopt.Flag([]string{"--force"}, []string{},
		"force replacement in binary files", "")
	showVersion = goopt.Flag([]string{"-V", "--version"}, []string{},
		"show version and exit", "")
	noIgnoresGlobal = goopt.Flag([]string{"-I", "--no-autoignore"}, []string{},
		"do not read .git/.hgignore files", "")
	verbose = goopt.Flag([]string{"-v", "--verbose"}, []string{},
		"be verbose (show non-fatal errors, like unreadable files)", "")
)
Example #3
0
File: zmqc.go Project: jhawk28/zmqc
	[]string{"-b", "--bind"},
	"Connect to the specified address(es).",
	"Bind to the specified address(es).")

var number = flag.Int([]string{"-n"}, -1, "Receive/send only NUM messages. By default, zmqc "+
	"lives forever in 'read' mode, or until the end of input "+
	"in 'write' mode.")

var socket_type = flag.Alternatives([]string{"-s"},
	[]string{"PUSH", "PULL", "PUB", "SUB", "REQ", "REP", "PAIR"},
	"Which type of socket to create. Must be one of 'PUSH', 'PULL', "+
		"'PUB', 'SUB', 'REQ', 'REP' or 'PAIR'. See `man zmq_socket` for an "+
		"explanation of the different types. 'DEALER' and 'ROUTER' sockets are "+
		"currently unsupported.")

var subscriptions = flag.Strings([]string{"--subscribe"}, "", "Subscribes to data matching")

func init() {
	flag.Version = "1.0"
	flag.Summary = "zmqc is a small but powerful command-line interface to " +
		"ZeroMQ. It allows you to create a socket of a given type, bind or " +
		"connect it to multiple addresses, set options on it, and receive or send " +
		"messages over it using standard I/O, in the shell or in scripts."
	flag.Author = "Joshua Foster"
}

func main() {
	flag.Parse(nil)

	address_list := flag.Args
	if len(address_list) == 0 {
Example #4
0
	goopt "github.com/droundy/goopt"
	"strings"
)

var amVerbose = goopt.Flag([]string{"--verbose"}, []string{},
	"output verbosely", "")
var amHappy = goopt.Flag([]string{"-h", "--happy"}, []string{"-u", "--unhappy", "--sad"}, "be happy", "be unhappy")

var foo = goopt.String([]string{"--name"}, "anonymous", "pick your name")
var bar = goopt.String([]string{"-b"}, "BOO!", "pick your scary sound")
var baz = goopt.String([]string{"-o"}, "", "test whether a silent default works")
var speed = goopt.Alternatives([]string{"--speed", "--velocity"},
	[]string{"slow", "medium", "fast"},
	"set the speed")

var words = goopt.Strings([]string{"--word", "--saying", "-w", "-s"}, "word",
	"specify a word to speak")

var width = goopt.Int([]string{"-l", "--length"}, 1, "number of ?s")

func main() {
	goopt.Summary = "silly test program"
	goopt.Parse(nil)
	if *amVerbose {
		fmt.Println("I am verbose.")
	}
	if *amHappy {
		fmt.Println("I am happy")
	} else {
		fmt.Println("I am unhappy")
	}
	fmt.Println("Your name is", *foo)
Example #5
0
package main

import (
	"exec"
	"fmt"
	"github.com/droundy/go-crazy/parser"
	"github.com/droundy/goopt"
	"go/printer"
	"os"
)

var just_translate = goopt.Flag([]string{"--just-translate"}, []string{},
	"just build the -compiled.go file", "build and compile and link")

var toinline = goopt.Strings([]string{"--inline"}, "FUNC", "specify function to inline")

func panicon(err os.Error) {
	if err != nil {
		panic(err)
	}
}

func archnum() string {
	switch os.Getenv("GOARCH") {
	case "386":
		return "8"
	case "amd64":
		return "6"
		// what was the other one called?
	}
	return "5"
Example #6
0
// decide whether or not to log anything.
func log(x ...interface{}) {
	if *amVerbose {
		fmt.Println(x...)
	}
}

var color = goopt.Alternatives([]string{"--color", "--colour"},
	[]string{"default", "red", "green", "blue"},
	"determine the color of the output")

var repetitions = goopt.Int([]string{"-n", "--repeat"}, 1, "number of repetitions")

var username = goopt.String([]string{"-u", "--user"}, "User", "name of user")

var children = goopt.Strings([]string{"--child"}, "name of child", "specify child of user")

func main() {
	goopt.Description = func() string {
		return "Example program for using the goopt flag library."
	}
	goopt.Version = "1.0"
	goopt.Summary = "goopt demonstration program"
	goopt.Parse(nil)
	defer fmt.Print("\033[0m") // defer resetting the terminal to default colors
	switch *color {
	case "default":
	case "red":
		fmt.Print("\033[31m")
	case "green":
		fmt.Print("\033[32m")