本文整理汇总了Golang中github.com/alecthomas/kingpin.Parse函数的典型用法代码示例。如果您正苦于以下问题:Golang Parse函数的具体用法?Golang Parse怎么用?Golang Parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Parse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
示例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)
}
示例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)
}
}
示例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)
}
}
示例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)
}
示例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")
}
}
示例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)
}
示例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)
}
示例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)
}
}
示例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())
// }
// }
}
示例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")
}
}
示例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")
}
}
示例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)
}
示例14: main
func main() {
kingpin.Version("0.2.1")
kingpin.Parse()
switch *format {
case "html":
openBrowser()
case "json":
fetchJSON()
default:
openBrowser()
}
}
示例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))
}