func main() { // Setup context ctx, cancel := context.WithCancel(context.Background()) defer cancel() // Define a CLI dcConfig := &DCConfig{ServiceIdentifier: "omnivore"} kingpin.Flag("n", "The index of this node in the pool, if IPFS_POOL_PATH is set").Default("-1").Short('n').IntVar(&dcConfig.PoolIndex) var args []string kingpin.Arg("args", "arguments").StringsVar(&args) kingpin.Parse() // Build a node ipfsNode, err := BuildNode(ctx, dcConfig) if err != nil { fmt.Println(err) os.Exit(1) } fmt.Printf("I am node %s\n", ipfsNode.Identity.Pretty()) // Respond to incoming providerIDs and streams // providerIDsIn, err := StartServiceDiscovery(ctx, ipfsNode, dcConfig) // if err != nil { // fmt.Println(err) // os.Exit(1) // } // // streamIn, err := StartListening(ipfsNode, dcConfig) // if err != nil { // fmt.Println(err) // os.Exit(1) // } // // for { // select { // case providerIDs := <-providerIDsIn: // for _, providerID := range providerIDs { // fmt.Printf("Provider: %s\n", providerID.Pretty()) // // stream, err := corenet.Dial(ipfsNode, providerID, dcConfig.ServiceIdentifier) // if err != nil { // fmt.Printf("Failed to dial provider %s (%s)\n", providerID.Pretty(), err) // continue // } // // fmt.Fprintf(stream, "Hello! I'm peer %s\n", ipfsNode.Identity.Pretty()) // stream.Close() // } // // case stream := <-streamIn: // fmt.Printf("Peer %s called!\n", stream.Conn().RemotePeer().Pretty()) // } // } }
package main import ( "fmt" "github.com/alecthomas/kingpin" ) var ( debug = kingpin.Flag("debug", "Enable debug mode.").Bool() timeout = kingpin.Flag("timeout", "Timeout waiting for ping.").OverrideDefaultFromEnvar("PING_TIMEOUT").Required().Short('t').Duration() ip = kingpin.Arg("ip", "IP address to ping.").Required().IP() count = kingpin.Arg("count", "Number of packets to send").Int() ) func main() { kingpin.Version("0.0.1") kingpin.Parse() fmt.Printf("Would ping: %s with timeout %s and count %d", *ip, *timeout, *count) }
"github.com/alecthomas/kingpin" "github.com/couchbaselabs/logg" ) //Config is the serialized config.json file type Config struct { SyncEndpoint string `json:"syncEndpoint"` Port int `json:"port"` Bucket string `json:"bucket"` TTL int `json:"ttl"` } var ( configFileDescription = "The name of the config file. Defaults to 'config.json'" configFileName = kingpin.Arg("config file name", configFileDescription).Default("config.json").String() config Config logTag = "SYNC_AUTH" ) func init() { // parse config file kingpin.Parse() if *configFileName == "" { kingpin.Errorf("Config file name missing") return } configFile, err := os.Open(*configFileName) if err != nil { logg.LogPanic("Unable to open file: %v. Err: %v", *configFileName, err.Error()) return
"fmt" "net/http" "log" "os" "github.com/alecthomas/kingpin" "github.com/gorilla/mux" "github.com/skarnecki/gotail/frontend" "github.com/skarnecki/gotail/pump" "golang.org/x/net/websocket" ) var ( filename = kingpin.Arg("filename", "Path to tailed file.").Required().ExistingFile() number = kingpin.Flag("number", "Starting lines number.").Default("10").Int() host = kingpin.Flag("host", "Listening host, default 0.0.0.0").Default("0.0.0.0").IP() port = kingpin.Flag("port", "listening port, default 9001").Default("9001").Int() cert = kingpin.Flag("cert", "path to cert file (HTTPS)").ExistingFile() key = kingpin.Flag("key", "path to key file (HTTPS)").ExistingFile() user = kingpin.Flag("user", "Basic auth user").String() password = kingpin.Flag("password", "Basic auth password").String() ) func main() { logger := log.New(os.Stdout, "logger: ", log.Lshortfile) kingpin.Parse() filechannel := make(chan string, 100) go pump.TailFile(filechannel, *filename)
package main import ( "log" "os" "os/user" "path/filepath" "strconv" "syscall" "github.com/alecthomas/kingpin" "github.com/go-fsnotify/fsnotify" ) var ( cliDir = kingpin.Arg("dir", "The directory to enforce permissions.").Required().String() cliChownUser = kingpin.Flag("chown-user", "Name of the user to Chown the directory with.").Required().String() cliChownGroup = kingpin.Flag("chown-group", "Name of group to Chown the directory with.").Required().String() cliChmodDir = kingpin.Flag("chmod-dir", "The mode to be assigned to directories.").Default("0775").Int64() cliChmodFile = kingpin.Flag("chmod-file", "The mode to be assigned to files.").Default("0664").Int64() uid int gid int ) func main() { kingpin.Parse() u, err := user.Lookup(*cliChownUser) if err != nil { panic(err)
package main import ( "github.com/alecthomas/kingpin" "github.com/cathalgarvey/buckfast/scrapedia" "github.com/cathalgarvey/buckfast/spritzlib" "io/ioutil" "log" "strings" ) var ( infile = kingpin.Arg("infile", "File to read. If prefixed with 'wikipedia:', fetches the corresponding wikipedia page instead (needs to be exact target page title)").Required().String() wpm = kingpin.Flag("wpm", "Approximate words per minute").Default("400").Short('w').Int() pivotColour = kingpin.Flag("pivot-colour", "Preferred pivot colour, one of red, green, blue, yellow, cyan, magenta, white, black."). Default("green"). Short('p'). Enum("red", "green", "blue", "cyan", "magenta", "yellow", "black", "white") //String() plainColour = kingpin.Flag("plain-colour", "Preferred non-pivot text colour, one of red, green, blue, yellow, cyan, magenta, white, black."). Default("white"). Short('P'). Enum("red", "green", "blue", "cyan", "magenta", "yellow", "black", "white") // String() bgColour = kingpin.Flag("background-colour", "Text background colour, one of red, green, blue, yellow, cyan, magenta, white, black."). Default(""). Short('b'). Enum("red", "green", "blue", "cyan", "magenta", "yellow", "black", "white") // String() boldText = kingpin.Flag("bold", "Whether to print bold.").Bool() )
String() keptEnvVars = kingpin. Flag("keep-env", "Add this environment variable to the list of variables that will be preserved from the calling process's environment. Defaults to an empty list, except TZ which will be set to \"UTC\"."). PlaceHolder("VARNAME"). Strings() loglevel = kingpin. Flag("loglevel", fmt.Sprintf("Set the desired level of logging (one of: %s).", strings.Join(loglevels, ", "))). Default("WARNING"). Enum(loglevels...) logstashPath = kingpin. Flag("logstash-path", "Set the path to the Logstash executable."). Default("/opt/logstash/bin/logstash"). String() // Arguments testcasePath = kingpin. Arg("testcases", "Test case file or a directory containing one or more test case files."). Required(). ExistingFileOrDir() configPaths = kingpin. Arg("config", "Logstash configuration file or a directory containing one or more configuration files."). Required(). ExistingFilesOrDirs() ) // runTests runs Logstash with a set of configuration files against a // slice of test cases and compares the actual events against the // expected set. Returns an error if at least one test case fails or // if there's a problem running the tests. func runTests(logstashPath string, tests []testcase.TestCase, configPaths []string, diffCommand []string, keptEnvVars []string) error { ok := true for _, t := range tests {
package main import ( "bufio" "fmt" "github.com/alecthomas/kingpin" "github.com/paocalvi/serial" "ibus" "os" "strings" ) var ( device = kingpin.Arg("device", "serial device to communicate with").Required().String() ) func main() { kingpin.Version("0.1") kingpin.Parse() ttyPath := *device fmt.Println("Writing packets to: " + ttyPath) fmt.Println("Packets are formatted all lower case hex, [src] [dest] [message...]") fmt.Println("Quote ascii strings for text conversion") serialConfig := &serial.Config{Name: ttyPath, Baud: 9600, Parity: serial.PARITY_EVEN} port, err := serial.OpenPort(serialConfig) if err != nil { panic(err) }
"os/signal" "strings" "syscall" "time" "github.com/alecthomas/kingpin" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/bluele/slack" ) const filename = "notified.json" var token = kingpin.Flag("token", "The slack API token").OverrideDefaultFromEnvar("TOKEN").Required().String() var timeout = kingpin.Arg("wait", "Wait in minutes before checking for changes").Default("10").Int() var expireTime = kingpin.Arg("expire", "Age in hours before notifing about the instance").Default("48").Int() var region = kingpin.Arg("region", "Amazon EC2 region to scan for instances").Default("eu-west-1").String() var prod = kingpin.Flag("prod", "Running for real?").OverrideDefaultFromEnvar("PROD").Default("false").Bool() func findUser(list []*slack.User, searchid string) string { for _, u := range list { if u.Id == searchid { return u.Id } if u.Profile.Email != "" { data := strings.Split(u.Profile.Email, "@") if data[0] == searchid { return u.Id }
func main() { cfg := new(initCfg) kingpin.Flag("n", "number of ipfs nodes to initialize").Short('n').IntVar(&cfg.Count) kingpin.Flag("port", "port to start allocations from").Default("4002").Short('p').IntVar(&cfg.PortStart) kingpin.Flag("force", "force initialization (overwrite existing configs)").Short('f').BoolVar(&cfg.Force) kingpin.Flag("mdns", "turn on mdns for nodes").BoolVar(&cfg.Mdns) kingpin.Flag("bootstrap", "select bootstrapping style for cluster").Default("star").StringVar(&cfg.Bootstrap) kingpin.Flag("utp", "use utp for addresses").BoolVar(&cfg.Utp) wait := kingpin.Flag("wait", "wait for nodes to come fully online before exiting").Bool() var args []string kingpin.Arg("args", "arguments").StringsVar(&args) kingpin.Parse() if len(args) == 0 { kingpin.Usage() return } switch args[0] { case "init": if cfg.Count == 0 { fmt.Printf("please specify number of nodes: '%s init -n 10'\n", os.Args[0]) os.Exit(1) } err := IpfsInit(cfg) handleErr("ipfs init err: ", err) case "start": err := IpfsStart(*wait) handleErr("ipfs start err: ", err) case "stop", "kill": if len(args) > 1 { i, err := strconv.Atoi(args[1]) if err != nil { fmt.Println("failed to parse node number: ", err) os.Exit(1) } err = KillNode(i) if err != nil { fmt.Println("failed to kill node: ", err) } return } err := IpfsKillAll() handleErr("ipfs kill err: ", err) case "restart": err := IpfsKillAll() handleErr("ipfs kill err: ", err) err = IpfsStart(*wait) handleErr("ipfs start err: ", err) case "shell": if len(args) < 2 { fmt.Println("please specify which node you want a shell for") os.Exit(1) } n, err := strconv.Atoi(args[1]) handleErr("parse err: ", err) err = IpfsShell(n) handleErr("ipfs shell err: ", err) case "connect": if len(args) < 3 { fmt.Println("iptb connect [node] [node]") os.Exit(1) } from, err := parseRange(args[1]) if err != nil { fmt.Printf("failed to parse: %s\n", err) return } to, err := parseRange(args[2]) if err != nil { fmt.Printf("failed to parse: %s\n", err) return } for _, f := range from { for _, t := range to { err = ConnectNodes(f, t) if err != nil { fmt.Printf("failed to connect: %s\n", err) return } } } case "get": if len(args) < 3 { fmt.Println("iptb get [attr] [node]") os.Exit(1) } attr := args[1] num, err := strconv.Atoi(args[2]) handleErr("error parsing node number: ", err) val, err := GetAttr(attr, num) handleErr("error getting attribute: ", err) fmt.Println(val) default: kingpin.Usage() fmt.Println(helptext) os.Exit(1) } }
package main import ( "fmt" "os" "github.com/alecthomas/kingpin" "github.com/parnurzeal/gorequest" "github.com/toqueteos/webbrowser" ) const htmlURL string = "http://kaifa.at/services/" const jsonURL string = "http://kaifa.at/api/services/" var ( keyword = kingpin.Arg("keyword", "Keyword of service").Required().String() format = kingpin.Flag("format", "Format: html,json").Default("html").String() ) func main() { kingpin.Version("0.2.1") kingpin.Parse() switch *format { case "html": openBrowser() case "json": fetchJSON() default: openBrowser() }
"fmt" "io/ioutil" "net" "os" "strings" "github.com/alecthomas/kingpin" "github.com/chzyer/readline" "github.com/joushou/qp" "github.com/joushou/qptools/client" ) var ( service = kingpin.Flag("service", "service name to use when connecting (aname)").Short('s').String() user = kingpin.Flag("user", "username to use when connecting (uname)").Short('u').String() address = kingpin.Arg("address", "address to connect to").Required().String() command = stringList(kingpin.Arg("command", "command to execute (disables interactive mode)")) rawtls = kingpin.Flag("rawtls", "wrap connection in TLS").Short('t').Bool() ) type slist []string func (i *slist) Set(value string) error { *i = append(*i, value) return nil } func (i *slist) String() string { return "" }
func Arg(name string, helpOptional ...string) *kingpin.ArgClause { help := strings.Join(helpOptional, " ") return kingpin.Arg(name, help) }
func parseArgs() Args { args := Args{} args.filename = kingpin.Arg("filename", "Name of file.").Required().String() kingpin.Parse() return args }
import ( "fmt" "os" "strconv" "github.com/alecthomas/kingpin" "github.com/nyushi/install" ) var ( owner = kingpin.Flag("owner", "").Short('o').String() group = kingpin.Flag("group", "").Short('g').String() mode = kingpin.Flag("mode", "").Short('m').String() dir = kingpin.Flag("directory", "").Short('d').Bool() _args = kingpin.Arg("src", "").Strings() ) func main() { kingpin.Parse() opt := &install.InstallOption{} if *owner != "" { opt.Owner = *owner } if *group != "" { opt.Group = *group } if *mode != "" { m, err := strconv.ParseInt(*mode, 8, 32) if err != nil {
package main import ( "fmt" "go/ast" "go/parser" "go/token" "io" "os" "github.com/alecthomas/kingpin" ) var ( inputFile = kingpin.Arg("source", "Input source file.").Required().String() outputFile = kingpin.Flag("output", "Where the generated code will be written.").Short('o').String() packageName = kingpin.Flag("package", "The output package name.").Short('p').Required().String() interfaceName = kingpin.Flag("interface", "The name of the interface that will be wrapped.").Short('i').Required().String() constructors = kingpin.Flag("constructor", "The name of a constructor that will be wrapped.").Short('c').Strings() ) func main() { var err error kingpin.Parse() parsed, err := parseFile(*inputFile) fatalError(err) writer := NewAgentWriter(*interfaceName, *packageName, parsed)