本文整理汇总了Golang中gopkg/in/alecthomas/kingpin/v2.Parse函数的典型用法代码示例。如果您正苦于以下问题:Golang Parse函数的具体用法?Golang Parse怎么用?Golang Parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Parse函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
kingpin.Parse()
if !contains(availableThemes, *theme) {
kingpin.Fatalf("theme: %s not found", *theme)
}
p, err := presentation.NewFromFileWithConfig(*source, *config)
ifErrFatal(err)
p.Theme = *theme
if *startDaemon {
r := mux.NewRouter()
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
ifErrFatal(p.Write(w))
if err := p.Reload(); err != nil {
w.WriteHeader(http.StatusInternalServerError)
}
})
r.PathPrefix("/").Handler(http.FileServer(http.Dir(".")))
port := ":" + strconv.Itoa(*port)
log.Println("Serving slides at", port)
log.Fatal(http.ListenAndServe(port, r))
return
}
// Write it just if we don't serve it
ifErrFatal(p.Write(*outputFile))
}
示例2: main
func main() {
kingpin.Parse()
if *startDaemon {
debug, _ = strconv.ParseBool(os.Getenv("DEBUG"))
rules, _ = loadRulesFromFile("rules.yaml")
log.Println("Daemon is listening in port", strconv.Itoa(*port))
http.HandleFunc("/validate", validateHandler)
http.HandleFunc("/setup", uploadHandler)
http.HandleFunc("/rules", uploadRulesHandler)
http.HandleFunc("/", defaultHandler)
http.ListenAndServe(":8080", nil)
} else {
rules, _ = loadRulesFromFile(*rulesFile)
dfile, _ := DockerfileFromPath(*dockerfile)
v := Validation{rules, dfile}
valid, msg := v.validate()
if valid {
fmt.Println("Dockerfile valid")
os.Exit(0)
} else {
fmt.Println("Docker file not vallid:", msg)
os.Exit(1)
}
}
}
示例3: main
func main() {
kingpin.Parse()
client := artifactory.NewClientFromEnv()
password := randPass()
var details artifactory.UserDetails = artifactory.UserDetails{
Email: *email,
Password: password,
}
if group != nil {
details.Groups = *group
}
if updatable != nil {
details.ProfileUpdatable = *updatable
}
err := client.CreateUser(*username, details)
if err != nil {
fmt.Printf("%s\n", err)
os.Exit(1)
} else {
if *showpass {
fmt.Printf("User created. Random password is: %s\n", password)
}
os.Exit(0)
}
}
示例4: main
func main() {
kingpin.Parse()
client := artifactory.NewClientFromEnv()
data, err := client.GetRepos(*kind)
if err != nil {
fmt.Printf("%s\n", err)
os.Exit(1)
} else {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{
"Key",
"Type",
"Description",
"Url",
})
for _, r := range data {
table.Append([]string{
r.Key,
r.Rtype,
r.Description,
r.Url,
})
}
table.Render()
os.Exit(0)
}
}
示例5: main
func main() {
kingpin.Parse()
client := rundeck.NewClientFromEnv()
data, err := client.GetJob(*jobid)
if err != nil {
fmt.Printf("%s\n", err)
} else {
scope := data.Job
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"ID", "Name", "Description", "Group", "Steps", "Node Filters"})
var steps []string
var nodefilters []string
for _, d := range scope.Sequence.Steps {
var stepDescription string
if d.Description == "" {
if d.JobRef != nil {
stepDescription = d.JobRef.Name
} else if d.Exec != nil {
stepDescription = *d.Exec
}
} else {
stepDescription = d.Description
}
steps = append(steps, stepDescription)
}
for _, n := range scope.NodeFilters.Filter {
nodefilters = append(nodefilters, n)
}
table.Append([]string{scope.ID, scope.Name, scope.Description, scope.Group, strings.Join(steps, "\n"), strings.Join(nodefilters, "\n")})
table.Render()
}
}
示例6: main
func main() {
kingpin.Parse()
client := artifactory.NewClientFromEnv()
u, err := client.GetUserDetails(*user)
if err != nil {
fmt.Printf("%s\n", err)
os.Exit(1)
} else {
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Name", "Email", "Password", "Admin?", "Updatable?", "Last Logged In", "Internal Password Disabled?", "Realm", "Groups"})
table.SetAutoWrapText(false)
table.Append([]string{
u.Name,
u.Email,
"<hidden>",
strconv.FormatBool(u.Admin),
strconv.FormatBool(u.ProfileUpdatable),
u.LastLoggedIn,
strconv.FormatBool(u.InternalPasswordDisabled),
u.Realm,
strings.Join(u.Groups, "\n"),
})
table.Render()
os.Exit(0)
}
}
示例7: init
func init() {
flag.Parse()
config.SetConfigFile(*configFileName)
err := config.ReadInConfig()
if err != nil {
panic("Config file not found")
}
logConfig := config.GetStringMap("log")
initLog(logConfig)
}
示例8: main
func main() {
kingpin.Version("0.1.1")
kingpin.Parse()
forwardEnabled := false
if *forwardhost != "" && *forwardport != "" {
forwardEnabled = true
}
log.Println("Clenaup interval ", *cleanupInterval)
serve(&MailServer{hostname: *hostname, port: *port, httpport: *webport, forwardEnabled: forwardEnabled, forwardHost: *forwardhost, forwardPort: *forwardport, expireinterval: *cleanupInterval})
}
示例9: main
func main() {
fmt.Println(buildInfo())
kingpin.Parse()
if *configPath == "" {
*configPath = "/etc/tinfoilhat/tinfoilhat.toml"
}
config, err := config.ReadConfig(*configPath)
if err != nil {
log.Fatalln("Cannot open config:", err)
}
db, err := steward.OpenDatabase(config.Database.Connection)
if err != nil {
log.Fatalln("Open database fail:", err)
}
defer db.Close()
db.SetMaxOpenConns(config.Database.MaxConnections)
switch kingpin.Parse() {
case "advisory list":
advisoryList(db)
case "advisory review":
advisoryReview(db)
case "advisory hide":
advisoryHide(db)
case "advisory unhide":
advisoryUnhide(db)
case "scoreboard":
scoreboardShow(db)
}
}
示例10: main
func main() {
fmt.Println(buildInfo())
kingpin.Parse()
if *configPath == "" {
log.Println("Use default config path")
*configPath = "/etc/tinfoilhat/tinfoilhat.toml"
}
config, err := config.ReadConfig(*configPath)
if err != nil {
log.Fatalln("Cannot open config:", err)
}
logFile, err := os.OpenFile(config.LogFile,
os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalln("Cannot open file:", err)
}
defer logFile.Close()
log.SetOutput(logFile)
log.Println(buildInfo())
var rlim syscall.Rlimit
err = syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlim)
if err != nil {
log.Fatalln("Getrlimit fail:", err)
}
log.Println("RLIMIT_NOFILE CUR:", rlim.Cur, "MAX:", rlim.Max)
db, err := steward.OpenDatabase(config.Database.Connection)
if err != nil {
log.Fatalln("Open database fail:", err)
}
defer db.Close()
db.SetMaxOpenConns(config.Database.MaxConnections)
if *dbReinit {
reinitDatabase(db, config)
}
checker.SetTimeout(config.CheckerTimeout.Duration)
if config.AdvisoryReceiver.Disabled {
scoreboard.DisableAdvisory()
}
priv, err := vexillary.GenerateKey()
if err != nil {
log.Fatalln("Generate key fail:", err)
}
attackFlow := make(chan scoreboard.Attack, config.API.AttackBuffer)
go receiver.FlagReceiver(db, priv, config.FlagReceiver.Addr,
config.FlagReceiver.ReceiveTimeout.Duration,
config.FlagReceiver.SocketTimeout.Duration,
attackFlow)
go receiver.AdvisoryReceiver(db, config.AdvisoryReceiver.Addr,
config.AdvisoryReceiver.ReceiveTimeout.Duration,
config.AdvisoryReceiver.SocketTimeout.Duration)
go scoreboard.Scoreboard(db, attackFlow,
config.Scoreboard.WwwPath,
config.Scoreboard.Addr,
config.Scoreboard.UpdateTimeout.Duration,
config.Pulse.Start.Time,
config.Pulse.Half.Duration,
config.Pulse.Lunch.Duration,
config.Pulse.DarkestTime.Duration)
err = pulse.Pulse(db, priv,
config.Pulse.Start.Time,
config.Pulse.Half.Duration,
config.Pulse.Lunch.Duration,
config.Pulse.RoundLen.Duration,
config.Pulse.CheckTimeout.Duration)
if err != nil {
log.Fatalln("Game error:", err)
}
log.Println("It's now safe to turn off you computer")
for {
time.Sleep(time.Hour)
}
}