本文整理汇总了Golang中github.com/alecthomas/kingpin.Parse函数的典型用法代码示例。如果您正苦于以下问题:Golang Parse函数的具体用法?Golang Parse怎么用?Golang Parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Parse函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
kingpin.Version(fmt.Sprintf("%s %s", kingpin.CommandLine.Name, version))
kingpin.Parse()
level, err := oplogging.LogLevel(*loglevel)
if err != nil {
prefixedUserError("Bad loglevel: %s", loglevel)
os.Exit(1)
}
logging.SetLevel(level)
diffCmd, err := shellwords.NewParser().Parse(*diffCommand)
if err != nil {
userError("Error parsing diff command %q: %s", *diffCommand, err.Error())
os.Exit(1)
}
tests, err := testcase.DiscoverTests(*testcasePath)
if err != nil {
userError(err.Error())
os.Exit(1)
}
if err = runTests(*logstashPath, tests, *configPaths, diffCmd, *keptEnvVars); err != nil {
userError(err.Error())
os.Exit(1)
}
os.Exit(0)
}
开发者ID:magnusbaeck,项目名称:logstash-filter-verifier,代码行数:28,代码来源:logstash-filter-verifier.go
示例2: main
func main() {
logger := log.New(os.Stdout, "logger: ", log.Lshortfile)
kingpin.Parse()
filechannel := make(chan string, 100)
go pump.TailFile(filechannel, *filename)
mainpage := &frontend.MainPage{HTTPSMode: false, BasicAuth: false, UserName: *user, UserPassword: *password}
if *user != "" && *password != "" {
mainpage.BasicAuth = true
}
if *cert != "" && *key != "" {
mainpage.HTTPSMode = true
}
logger.Printf("Basic auth: %t", mainpage.BasicAuth)
logger.Printf("HTTPS: %t", mainpage.HTTPSMode)
handler := pump.WebHandler{Filechannel: filechannel, Buffer: make([]string, *number), BufferSize: *number}
address := fmt.Sprintf("%s:%d", *host, *port)
r := mux.NewRouter()
r.Handle("/", mainpage)
r.Handle("/socket", websocket.Handler(handler.Websocket))
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(assetFS())))
http.Handle("/", r)
logger.Printf("Listening on %s\n", address)
if *cert != "" && *key != "" {
http.ListenAndServeTLS(address, *cert, *key, nil)
}
http.ListenAndServe(address, nil)
}
开发者ID:skarnecki,项目名称:gotail,代码行数:32,代码来源:app.go
示例3: main
func main() {
kingpin.Version(Version)
kingpin.Parse()
setupLoggo(*debug)
//localRegistry := metrics.NewRegistry()
//publisher := newPublisher(localRegistry)
//publisher := newLitePublisher()
mqttEngine, mqerr := newMqttEngine(*mqttURL)
wbEngine, wberr := NewWebBrickDriver(mqttEngine)
if mqerr != nil && wberr != nil {
panic(err)
}
wbEngine.Start()
//ws := newWsServer(localRegistry)
//go ws.listenAndServ(*port, *path)
// Set up channel on which to send signal notifications.
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, os.Interrupt, os.Kill)
// Wait for receiving a signal.
<-sigc
// Disconnect the Network Connection.
if err := engine.disconnect(); err != nil {
panic(err)
}
}
开发者ID:paulcull,项目名称:mqtt-webbrick,代码行数:35,代码来源:main.go
示例4: init
func init() {
//set logging
logg.LogKeys[TagError] = true
logg.LogKeys[TagDiff] = true
if DEBUG == false {
logg.LogKeys[TagLog] = true
}
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
}
defer configFile.Close()
configReader := bufio.NewReader(configFile)
err = parseConfigFile(configReader)
if err != nil {
logg.LogPanic("Erro parsing the config file: %v", err)
}
}
开发者ID:Ryanair,项目名称:fr-mobile-resource-cache,代码行数:28,代码来源:main.go
示例5: main
func main() {
//Parse command line flags
var (
_host = kingpin.Flag("host", "Hostname").Short('h').Required().String()
_port = kingpin.Flag("port", "Port number").Short('p').Required().Int()
_threads = kingpin.Flag("threads", "Thread count").Short('t').Default("1").Int()
_size = kingpin.Flag("size", "Packet Size").Short('s').Default("65507").Int()
)
kingpin.Parse()
fullAddr := fmt.Sprintf("%s:%v", *_host, *_port)
//Create send buffer
var buf []byte = make([]byte, *_size)
//Establish udp
conn, err := net.Dial("udp", fullAddr)
if err != nil {
fmt.Println(err)
} else {
fmt.Printf("Flooding %s\n", fullAddr)
for i := 0; i < *_threads; i++ {
go func() {
for {
conn.Write(buf)
}
}()
}
}
//Sleep forever
<-make(chan bool, 1)
}
开发者ID:TWSSYesterday,项目名称:udpflood,代码行数:32,代码来源:udpflood.go
示例6: main
func main() {
kingpin.Parse()
if *train {
println("START")
start := time.Now().UnixNano()
ptrain := NewHMMParser("training/training.set")
println("Training set loaded")
ptrain.fParseTrainer()
println("Training set trained")
ptrain.Save()
stop := time.Now().UnixNano()
println("training delta", (stop-start)/1000, "mics")
} else {
println("Loading model " + *model)
hmmParser := NewHMMParser(*model)
hmmParser.Load()
hmm := NewHMM(hmmParser)
println("Model " + *model + " loaded")
start := time.Now().UnixNano()
ws := strings.Split("<s> "+*text, " ")
hmm.fViterbi(ws)
println(hmm.String())
stop := time.Now().UnixNano()
println("test delta", (stop-start)/1000, "mics")
}
}
开发者ID:lessc0de,项目名称:go-postagger,代码行数:27,代码来源:gopostagger.go
示例7: main
func main() {
kingpin.Parse()
u, err := user.Lookup(*cliChownUser)
if err != nil {
panic(err)
}
g, err := user.Lookup(*cliChownGroup)
if err != nil {
panic(err)
}
uid, err = strconv.Atoi(u.Uid)
if err != nil {
panic(err)
}
gid, err = strconv.Atoi(g.Gid)
if err != nil {
panic(err)
}
// Ensure all folders and files are currently set to the correct permissions.
filepath.Walk(*cliDir, update)
// Now we will wait for
watch(*cliDir)
}
开发者ID:nickschuch,项目名称:permissions,代码行数:29,代码来源:main.go
示例8: main
func main() {
var (
bcontent []byte
content string
err error
)
kingpin.Parse()
if strings.HasPrefix(*infile, "wikipedia:") {
log.Println("Fetching from wikipedia:", strings.TrimPrefix(*infile, "wikiedia:"))
content, err = scrapedia.GetMainText("https://en.wikipedia.org/wiki/" + strings.TrimPrefix(*infile, "wikipedia:"))
} else {
// Default: assume plaintext file and load contents.
log.Println("Opening plaintext file: " + *infile)
bcontent, err = ioutil.ReadFile(*infile)
content = string(bcontent)
}
if err != nil {
log.Fatal(err.Error())
}
log.Println("Beginning at", *wpm, "words per minute..")
took_seconds, total_wds, final_wpm, err := spritzlib.RenderSpritzed(string(content), *wpm, *boldText, colourNameToCode(*pivotColour), colourNameToCode(*plainColour), colourNameToCode(*bgColour))
if err != nil {
log.Fatal(err.Error())
}
log.Println("Finished reading", total_wds, "words in", took_seconds, "seconds")
log.Println("Final wpm:", final_wpm)
}
开发者ID:cathalgarvey,项目名称:buckfast,代码行数:27,代码来源:main.go
示例9: main
func main() {
var err error
kingpin.Parse()
parsed, err := parseFile(*inputFile)
fatalError(err)
writer := NewAgentWriter(*interfaceName, *packageName, parsed)
var out io.Writer
if *outputFile == "" {
out = os.Stdout
} else {
out, err = os.Create(*outputFile)
fatalError(err)
}
WriteCodeGenerationWarning(out)
writer.WritePackageName(out)
WriteLibImport(out)
writer.WriteAgentType(out)
writer.WriteAgentMethods(out)
writer.WriteAgentControl(out)
writer.WriteRunLoop(out)
for _, constructor := range *constructors {
writer.WriteConstructor(out, constructor)
}
}
开发者ID:tokenshift,项目名称:gogogadget,代码行数:31,代码来源:main.go
示例10: main
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())
// }
// }
}
开发者ID:confiks,项目名称:ipfs-dc,代码行数:57,代码来源:main.go
示例11: main
func main() {
kingpin.CommandLine.Help = "An example implementation of curl."
switch kingpin.Parse() {
case "get":
kingpin.FatalIfError(apply("GET", (*getURL).String()), "GET failed")
case "post":
kingpin.FatalIfError(applyPOST(), "POST failed")
}
}
开发者ID:jessereynolds,项目名称:coco,代码行数:10,代码来源:curl.go
示例12: main
func main() {
kingpin.UsageTemplate(kingpin.CompactUsageTemplate).Version("1.0").Author("Alec Thomas")
kingpin.CommandLine.Help = "An example implementation of curl."
switch kingpin.Parse() {
case "get url":
kingpin.FatalIfError(apply("GET", (*getURLURL).String()), "GET failed")
case "post":
kingpin.FatalIfError(applyPOST(), "POST failed")
}
}
开发者ID:albertrdixon,项目名称:transmon,代码行数:11,代码来源:main.go
示例13: main
func main() {
kingpin.Parse()
config, err := config.LoadConfiguration(*configurationPath)
if err != nil {
log.Fatal(err)
}
youppi := slackscot.NewSlackscot([]slackscot.ExtentionBundle{brain.NewKarma(), brain.NewImager()})
slackscot.Run(*youppi, *config)
}
开发者ID:timoman,项目名称:youppi,代码行数:12,代码来源:youppi.go
示例14: main
func main() {
kingpin.Version("0.2.1")
kingpin.Parse()
switch *format {
case "html":
openBrowser()
case "json":
fetchJSON()
default:
openBrowser()
}
}
开发者ID:kaifali,项目名称:cli,代码行数:13,代码来源:kaifa.go
示例15: main
func main() {
kingpin.CommandLine.Help = "Docker container EC2 metadata service."
kingpin.Parse()
defer log.Flush()
configureLogging(*verboseOpt)
auth, err := aws.GetAuth("", "", "", time.Time{})
if err != nil {
panic(err)
}
containerService := NewContainerService(dockerClient(), *defaultRole, auth)
// Proxy non-credentials requests to primary metadata service
http.HandleFunc("/", logHandler(func(w http.ResponseWriter, r *http.Request) {
match := credsRegex.FindStringSubmatch(r.URL.Path)
if match != nil {
handleCredentials(match[1], match[2], containerService, w, r)
return
}
proxyReq, err := http.NewRequest(r.Method, fmt.Sprintf("%s%s", baseUrl, r.URL.Path), r.Body)
if err != nil {
log.Error("Error creating proxy http request: ", err)
http.Error(w, "An unexpected error occurred communicating with Amazon", http.StatusInternalServerError)
return
}
copyHeaders(proxyReq.Header, r.Header)
resp, err := instanceServiceClient.RoundTrip(proxyReq)
if err != nil {
log.Error("Error forwarding request to EC2 metadata service: ", err)
http.Error(w, "An unexpected error occurred communicating with Amazon", http.StatusInternalServerError)
return
}
defer resp.Body.Close()
copyHeaders(w.Header(), resp.Header)
w.WriteHeader(resp.StatusCode)
if _, err := io.Copy(w, resp.Body); err != nil {
log.Warn("Error copying response content from EC2 metadata service: ", err)
}
}))
log.Critical(http.ListenAndServe(*serverAddr, nil))
}
开发者ID:flyinprogrammer,项目名称:docker-ec2-metadata,代码行数:51,代码来源:main.go
示例16: main
func main() {
kingpin.Version("0.1")
kingpin.Parse()
f, err := os.OpenFile(*logfile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
if err != nil {
panic(err)
}
defer f.Close()
LogInit(f)
GetClusterReport(*conf)
}
开发者ID:theanalyst,项目名称:ceph-mon-alert,代码行数:14,代码来源:main.go
示例17: main
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)
}
go func() {
parser := ibus.NewIbusPacketParser()
for {
buffer := make([]byte, 1)
_, err := port.Read(buffer)
if err != nil {
panic(err)
}
parser.Push(buffer)
if parser.HasPacket() {
pkt := parser.GetPacket()
// echo received packets to simulate bus broadcast
port.Write(pkt.AsBytes())
fmt.Println("\n<== " + pkt.AsString())
fmt.Print("Enter IBUS packet: ")
}
}
}()
for {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter IBUS packet: ")
text, _ := reader.ReadString('\n')
text = strings.TrimSpace(text)
hexChars := strings.Split(text, " ")
packet := new(ibus.IbusPacket)
packet.Src = hexChars[0]
packet.Dest = hexChars[1]
packet.Message = hexChars[2:len(hexChars)]
fmt.Println("==> " + packet.AsString())
bytes := packet.AsBytes()
port.Write(bytes)
}
}
开发者ID:jimbojsb,项目名称:ibus-simulator,代码行数:50,代码来源:ibus.go
示例18: main
func main() {
bsize := kingpin.Flag("blocksize", "blocksize to test with").Default("262144").Int64()
kingpin.Parse()
ipfsdir := getIpfsDir()
r, err := fsrepo.Open(ipfsdir)
if err != nil {
fmt.Printf("Failed to open ipfs repo at: %s: %s\n", ipfsdir, err)
fmt.Println("Please ensure ipfs has been initialized and that no daemon is running")
return
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
nd, err := core.NewNode(ctx, &core.BuildCfg{
Repo: r,
})
if err != nil {
fmt.Printf("failed to create node: %s\n", err)
return
}
cfg := &BenchCfg{
Blocksize: *bsize,
}
fmt.Println(cfg)
err = BenchmarkBlockRewrites(nd, cfg)
if err != nil {
panic(err)
}
err = BenchmarkRandomBlockWrites(nd, cfg)
if err != nil {
panic(err)
}
err = BenchmarkAdd(nd, cfg)
if err != nil {
panic(err)
}
err = BenchmarkDiskWrites(ipfsdir)
if err != nil {
panic(err)
}
}
开发者ID:whyrusleeping,项目名称:repobench,代码行数:48,代码来源:main.go
示例19: main
func main() {
kingpin.Version("0.1")
kingpin.Parse()
f, err := os.OpenFile(*logfile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
if err != nil {
panic(err)
}
defer f.Close()
LogInit(*verbose, f)
osd_sockets, err := filepath.Glob(*osd_sockets)
if err != nil {
log.Error("No sockets found exiting")
}
log.Info("Found following sockets", osd_sockets)
c := make(chan perf)
perfcounters := make([]PerfCounter, len(osd_sockets))
for _, osd_socket := range osd_sockets {
go func() {
result, err := QueryAdminSocket(osd_socket)
if err != nil {
log.Fatal("Querying Socket failed with ", err)
}
c <- perf{*result, err}
}()
query := <-c
if query.error == nil {
perfcounters = append(perfcounters, query.PerfCounter)
// perf_json, err := json.Marshal(query.PerfCounter)
// if err == nil {
// fmt.Println(string(perf_json))
// }
token, err := get_token()
if err == nil {
PostPerfCeilometer(token, query.PerfCounter)
}
}
}
GetClusterStatus(*conf)
GetClusterIOPs(*conf)
}
开发者ID:hkumarmk,项目名称:rlyeh,代码行数:47,代码来源:main.go
示例20: parseFlags
func parseFlags() {
kingpin.HelpFlag.Short('h')
kingpin.Version(versionMessage())
kingpin.Flag("root", "root directory").Short('r').Default("./").StringVar(&gcfg.Root)
kingpin.Flag("addr", "listen address").Short('a').Default(":8000").StringVar(&gcfg.Addr)
kingpin.Flag("cert", "tls cert.pem path").StringVar(&gcfg.Cert)
kingpin.Flag("key", "tls key.pem path").StringVar(&gcfg.Key)
kingpin.Flag("httpauth", "HTTP basic auth (ex: user:pass)").Default("").StringVar(&gcfg.HttpAuth)
kingpin.Flag("theme", "web theme, one of <black|green>").Default("black").StringVar(&gcfg.Theme)
kingpin.Flag("upload", "enable upload support").BoolVar(&gcfg.Upload)
kingpin.Flag("xheaders", "used when behide nginx").BoolVar(&gcfg.XHeaders)
kingpin.Flag("cors", "enable cross-site HTTP request").BoolVar(&gcfg.Cors)
kingpin.Flag("plistproxy", "plist proxy when server is not https").Default(defaultPlistProxy).Short('p').URLVar(&gcfg.PlistProxy)
kingpin.Flag("title", "server title").Default("Go HTTP File Server").StringVar(&gcfg.Title)
kingpin.Parse()
}
开发者ID:RainYang0925,项目名称:gohttpserver,代码行数:17,代码来源:main.go
注:本文中的github.com/alecthomas/kingpin.Parse函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论