本文整理汇总了Golang中flag.Bool函数的典型用法代码示例。如果您正苦于以下问题:Golang Bool函数的具体用法?Golang Bool怎么用?Golang Bool使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Bool函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
servers := flag.String("servers", "", "zk servers")
chroot := flag.String("chroot", "", "zk chroot")
recursive := flag.Bool("r", false, "recursive ?")
help := flag.Bool("h", false, "help info")
flag.Parse()
if *help {
printUsage()
os.Exit(0)
}
if len(*servers) == 0 {
fmt.Println("ERROR: --servers is required\n")
printUsage()
os.Exit(255)
}
if flag.NArg() < 2 {
fmt.Println("ERROR: cmd path is requred\n")
printUsage()
os.Exit(255)
}
opt := cmd.NewCmdOption()
opt.Servers = strings.Split(*servers, ",")
opt.Chroot = *chroot
opt.Recursive = *recursive
err := cmd.Call(opt, flag.Args())
if err != nil {
fmt.Println("ERROR: fail to zk:", err)
os.Exit(255)
}
os.Exit(0)
}
开发者ID:dzch,项目名称:zkcli,代码行数:31,代码来源:zkcli.go
示例2: main
func main() {
algo := flag.Int("a", 256, "SHA hash algorithm (one of 256, 384, or 512)")
check := flag.Bool("c", false, "read SHA sums from the files and check them")
hidden := flag.Bool("d", false, "sum hidden (dot) files")
flag.Parse()
progName = filepath.Base(os.Args[0])
sumHidden = *hidden
switch *algo {
case 1:
sumFunc = sum1
case 256:
sumFunc = sum256
case 384:
sumFunc = sum384
case 512:
sumFunc = sum512
default:
fmt.Println("Unrecognised algorithm.")
os.Exit(1)
}
if *check {
checkFile(flag.Args())
} else {
for _, root := range flag.Args() {
err := filepath.Walk(root, walker)
if err != nil {
fmt.Printf("%v\n", err)
}
}
}
}
开发者ID:postfix,项目名称:rshasum,代码行数:34,代码来源:sum.go
示例3: main
func main() {
swaggerDir := flag.String("path", "", "Path to model files")
buildStructs := flag.Bool("structs", true, "Whether or not to build structs")
buildAPI := flag.Bool("api", true, "Whether or not to build the API")
flag.Parse()
files, err := ioutil.ReadDir(*swaggerDir)
if err != nil {
log.Fatal(err)
}
for _, swaggerFile := range files {
if !swaggerFile.IsDir() && strings.HasSuffix(swaggerFile.Name(), ".json") {
apiBase := strings.TrimSuffix(swaggerFile.Name(), ".json")
swaggerPath := strings.Join([]string{*swaggerDir, swaggerFile.Name()}, "/")
swaggerString, err := ioutil.ReadFile(swaggerPath)
if err != nil {
continue
}
var s Swagger
json.Unmarshal(swaggerString, &s)
ParseModels(s.Models.(map[string]interface{}))
BuildAPIs(apiBase, s)
}
}
fmt.Println("package ari")
if *buildAPI {
fmt.Println(apiPreamble)
}
if *buildStructs {
OutputStructs()
}
if *buildAPI {
fmt.Print(clientAPIBuf.String())
}
}
开发者ID:nvisibleinc,项目名称:go-ari-struct-builder,代码行数:34,代码来源:go-ari-struct-builder.go
示例4: main
func main() {
cfg := flag.String("c", "cfg.json", "configuration file")
version := flag.Bool("v", false, "show version")
versionGit := flag.Bool("vg", false, "show version")
flag.Parse()
if *version {
fmt.Println(g.VERSION)
os.Exit(0)
}
if *versionGit {
fmt.Println(g.VERSION, g.COMMIT)
os.Exit(0)
}
// global config
g.ParseConfig(*cfg)
// proc
proc.Start()
// monitor
monitor.Start()
// http
http.Start()
select {}
}
开发者ID:Cepave,项目名称:anteye,代码行数:28,代码来源:main.go
示例5: main
func main() {
debug := flag.Bool("debug", false, "debug on")
threaded := flag.Bool("threaded", true, "debug on")
delcache_ttl := flag.Float64("deletion_cache_ttl", 5.0, "Deletion cache TTL in seconds.")
branchcache_ttl := flag.Float64("branchcache_ttl", 5.0, "Branch cache TTL in seconds.")
deldirname := flag.String(
"deletion_dirname", "GOUNIONFS_DELETIONS", "Directory name to use for deletions.")
flag.Parse()
if len(flag.Args()) < 2 {
fmt.Println("Usage:\n main MOUNTPOINT RW-DIRECTORY RO-DIRECTORY ...")
os.Exit(2)
}
ufsOptions := unionfs.UnionFsOptions{
DeletionCacheTTLSecs: *delcache_ttl,
BranchCacheTTLSecs: *branchcache_ttl,
DeletionDirName: *deldirname,
}
ufs, err := unionfs.NewUnionFsFromRoots(flag.Args()[1:], &ufsOptions)
if err != nil {
log.Fatal("Cannot create UnionFs", err)
os.Exit(1)
}
mountState, _, err := fuse.MountFileSystem(flag.Arg(0), ufs, nil)
if err != nil {
log.Fatal("Mount fail:", err)
}
mountState.Debug = *debug
mountState.Loop(*threaded)
}
开发者ID:jravasi,项目名称:go-fuse,代码行数:33,代码来源:main.go
示例6: main
func main() {
userFlag := flag.Bool("add_user", false, "Run CLI for adding user to database")
testFlag := flag.Bool("test", false, "Run test script to simulate client")
flag.Parse()
// Connect to database
data := os.Getenv("OPENSHIFT_DATA_DIR")
db := models.InitDb(data+"ota.sql", data+"builds")
defer db.Db.Close()
go models.RefreshBuilds()
if *testFlag {
tests.TestServer("http://localhost:8080")
} else {
if *userFlag {
// Start CLI to create new user account
addUser()
} else {
// Start server
templates := "./views"
controllers.InitMiddleware(templates)
server(templates)
}
}
}
开发者ID:sanshao27,项目名称:android_ota_manager,代码行数:26,代码来源:android_ota_manager.go
示例7: TestParse_Global
func TestParse_Global(t *testing.T) {
resetForTesting("")
os.Setenv(envTestPrefix+"D", "EnvD")
os.Setenv(envTestPrefix+"E", "true")
os.Setenv(envTestPrefix+"F", "5.5")
flagA := flag.Bool("a", false, "")
flagB := flag.Float64("b", 0.0, "")
flagC := flag.String("c", "", "")
flagD := flag.String("d", "", "")
flagE := flag.Bool("e", false, "")
flagF := flag.Float64("f", 0.0, "")
parse(t, "./testdata/global.ini", envTestPrefix)
if !*flagA {
t.Errorf("flagA found %v, expected true", *flagA)
}
if *flagB != 5.6 {
t.Errorf("flagB found %v, expected 5.6", *flagB)
}
if *flagC != "Hello world" {
t.Errorf("flagC found %v, expected 'Hello world'", *flagC)
}
if *flagD != "EnvD" {
t.Errorf("flagD found %v, expected 'EnvD'", *flagD)
}
if !*flagE {
t.Errorf("flagE found %v, expected true", *flagE)
}
if *flagF != 5.5 {
t.Errorf("flagF found %v, expected 5.5", *flagF)
}
}
开发者ID:ngdinhtoan,项目名称:globalconf,代码行数:35,代码来源:globalconf_test.go
示例8: main
func main() {
// Parse flags.
var port int
var vlc *bool
var seed *bool
vlc = flag.Bool("vlc", false, "Open vlc to play the file")
flag.IntVar(&port, "port", 8080, "Port to stream the video on")
seed = flag.Bool("seed", false, "Seed after finished downloading")
flag.Parse()
if len(flag.Args()) == 0 {
flag.Usage()
os.Exit(exitNoTorrentProvided)
}
// Start up the torrent client.
client, err := NewClient(flag.Arg(0), port, *seed)
if err != nil {
log.Fatalf(err.Error())
os.Exit(exitErrorInClient)
}
// Http handler.
go func() {
http.HandleFunc("/", client.GetFile)
log.Fatal(http.ListenAndServe(":"+strconv.Itoa(port), nil))
}()
// Open vlc to play.
if *vlc {
go func() {
for !client.ReadyForPlayback() {
time.Sleep(time.Second)
}
playInVlc(port)
}()
}
// Handle exit signals.
interruptChannel := make(chan os.Signal, 1)
signal.Notify(interruptChannel,
os.Interrupt,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
go func(interruptChannel chan os.Signal) {
for range interruptChannel {
log.Println("Exiting...")
client.Close()
os.Exit(0)
}
}(interruptChannel)
// Cli render loop.
for {
client.Render()
time.Sleep(time.Second)
}
}
开发者ID:thesyncim,项目名称:go-peerflix,代码行数:60,代码来源:main.go
示例9: main
func main() {
verbose := flag.Bool("verbose", false, "Verbose mode")
help := flag.Bool("help", false, "Show usage")
flag.Usage = usage
flag.Parse()
initialPath := flag.Arg(0)
if initialPath == "" {
initialPath = "./"
}
if _, err := os.Stat(initialPath); err != nil {
application.Fatal(err.Error())
}
application.Verbose = *verbose
if *help {
usage()
return
}
watcherLoop := newWatcherLoop(initialPath)
application.Register("Watcher Loop", watcherLoop)
application.InstallSignalHandler(&sigterm{paths: watcherLoop.paths})
exitCh := make(chan bool)
application.Run()
<-exitCh
}
开发者ID:remogatto,项目名称:prettytest,代码行数:27,代码来源:main.go
示例10: Do
// Do the plugin
func Do() {
optHost := flag.String("host", "localhost", "Hostname")
optPort := flag.String("port", "3306", "Port")
optSocket := flag.String("socket", "", "Port")
optUser := flag.String("username", "root", "Username")
optPass := flag.String("password", "", "Password")
optTempfile := flag.String("tempfile", "", "Temp file name")
optInnoDB := flag.Bool("disable_innodb", false, "Disable InnoDB metrics")
optMetricKeyPrefix := flag.String("metric-key-prefix", "mysql", "metric key prefix")
optEnableExtended := flag.Bool("enable_extended", false, "Enable Extended metrics")
flag.Parse()
var mysql MySQLPlugin
if *optSocket != "" {
mysql.Target = *optSocket
mysql.isUnixSocket = true
} else {
mysql.Target = fmt.Sprintf("%s:%s", *optHost, *optPort)
}
mysql.Username = *optUser
mysql.Password = *optPass
mysql.DisableInnoDB = *optInnoDB
mysql.prefix = *optMetricKeyPrefix
mysql.EnableExtended = *optEnableExtended
helper := mp.NewMackerelPlugin(mysql)
helper.Tempfile = *optTempfile
helper.Run()
}
开发者ID:supercaracal,项目名称:mackerel-agent-plugins,代码行数:30,代码来源:mysql.go
示例11: init
func init() {
// All the defaults mentioned here refer to etcd_load.cfg values.
fhelp = flag.Bool("help", false, "shows how to use flags")
fhost = flag.String("h", "null", "etcd instance address."+
"Default=127.0.0.1 from config file")
fport = flag.String("p", "null",
"port on which etcd is running. Defalt=4001")
foperation = flag.String("o", "null",
"operation - create/delete/get/update. Default:create")
fkeycount = flag.Int("k", -1, "number of keys involved in operation,"+
"useful for create. Default:100")
foperation_count = flag.Int("oc", -1, "number of operations to be performed,"+
" Default:100")
flog_file = flag.String("log", "null", "logfile name, default : log")
fremote_flag = flag.Bool("remote", false, " Must be set true if etcd "+
"instance is remote. Default=false")
fmem_flag = flag.Bool("mem", false, "When true, memory info is shown."+
" Default=false")
fsecure = flag.Bool("secure", false, "When true, new tls client created "+
"using certificate,key files. Default = false")
fcfg_file = flag.String("c", "null", "Input the cfg file. Required")
fcapath = flag.String("capath", "null", "Certificate Path"+
". Default = /etc/openshift/master")
fcacert = flag.String("ca", "ca.crt", "The ca filename. Default = ca.crt")
fclient_cert = flag.String("cert", "null", "The client"+
"Certificate. Default = master.etcd-client.crt")
fclient_key = flag.String("cakey", "null", "The client"+
"Key file. Default = master.etcd-client.key")
}
开发者ID:smalleni,项目名称:etcd-load-generator,代码行数:29,代码来源:etcd_load.go
示例12: main
func main() {
mongodAddr := flag.String("addr", "127.0.0.1:27017", "-addr=127.0.0.1:27017")
switchFind := flag.Bool("find", false, "-find")
switchMapReduce := flag.Bool("mapreduce", false, "-mapreduce")
switchInsert := flag.Bool("insert", false, "-insert")
switchInit := flag.Bool("init", false, "-init")
switchTree := flag.Bool("tree", false, "-tree")
flag.Parse()
session, err := mgo.Dial(*mongodAddr)
if err != nil {
panic(err)
}
defer session.Close()
dbName := "study"
collectionName := "test1"
db := session.DB(dbName)
collection := db.C(collectionName)
if *switchFind {
find(collection)
} else if *switchMapReduce {
mapreduce(collection)
} else if *switchInsert {
insert(collection)
} else if *switchInit {
initCollection(collection, 10000)
} else if *switchTree {
tree(db)
} else {
flag.PrintDefaults()
}
}
开发者ID:cst05001,项目名称:studymgo,代码行数:34,代码来源:main.go
示例13: main
func main() {
var flagRunLanguageTests = flag.Bool("test", false, "Run the language sanity tests")
var testLanguage = flag.String("lang", "", "Run the tests for one specific language")
var disableApparmor = flag.Bool("disable-apparmor", false, "Disable all apparmor usage. NOT FOR PROD obv.")
flag.Parse()
if *disableApparmor {
fmt.Printf("Running without apparmor support!\n")
}
engine, err := engine.New("config", *disableApparmor)
if err != nil {
panic(err)
}
// go func() {
// for {
// time.Sleep(15 * time.Second)
// fmt.Printf("\n\n========\n")
// pprof.Lookup("goroutine").WriteTo(os.Stderr, 1)
// }
// }()
if *flagRunLanguageTests {
runLanguageTests(engine, *testLanguage)
} else {
startServer(engine, ":8081")
}
}
开发者ID:instructure,项目名称:straitjacket,代码行数:29,代码来源:main.go
示例14: main
/*
* Run the program
*
* Usage:
* ./ls [args] directory_name
*
* possible args:
* -R: go through directories recursively
* -n: print with information
* -t: sort files by modification time
*
* if no arguments are getting, print out alphabetically with 1 file
* per line
*/
func main() {
var R *bool
var n *bool
var t *bool
R = flag.Bool("R", false, "go through directories recursively")
n = flag.Bool("n", false, "print with information")
t = flag.Bool("t", false, "sort files by modification time")
flag.Parse()
args := flag.Args()
if len(args) == 0 {
args = []string{"./"}
}
defer func() {
if r := recover(); r != nil {
fmt.Fprintln(os.Stderr, "Invalid Arguments")
}
}()
temp := template.Must(template.New("ls").Parse("{{.Mode}} {{printf `%3d` .Nlink}} {{.Uid}} {{.Gid}} {{printf `%7d` .Size}} {{.Mtime}} {{.Name}}\n"))
for _, arg := range args {
if data, error := ls.Ls(arg, *R, *t); error == nil {
path := data[0][0].Name
if strings.HasSuffix(path, "/") {
path = path[0 : len(path)-1]
}
printFiles(flag.NArg(), data, path, n, temp)
} else {
fmt.Fprintln(os.Stderr, "File or directory not found")
}
}
}
开发者ID:Altece,项目名称:Go-Go-Gadget-Repo,代码行数:48,代码来源:main.go
示例15: main
func main() {
var lineNumFlag = flag.Bool("n", false, "output line numbers")
var tabFlag = flag.Bool("t", false, "display tabs")
flag.Parse()
args := flag.Args()
flags := 0
if *lineNumFlag {
flags += 2
}
if *tabFlag {
flags += 1
}
for _, arg := range args {
file, err := os.Open(arg)
if err != nil {
return
}
fileStat, err := file.Stat()
if err != nil {
return
}
size := int(fileStat.Sys().(*syscall.Stat_t).Blksize)
outBuf := NewTempWriter(int(fileStat.Sys().(*syscall.Stat_t).Blksize))
inBuf := make([]byte, size)
Cat(file, inBuf, outBuf, flags)
file.Close()
outBuf.Flush()
}
return
}
开发者ID:kavinderd,项目名称:cat,代码行数:34,代码来源:cat.go
示例16: main
func main() {
version := flag.Bool("version", false, "Print version and exit")
list := flag.Bool("list", false, "List config vars")
netaddr := flag.String("netaddr", "tcp:127.0.0.1:6379", "Redis netaddr (e.g. tcp:120.0.0.1:6379")
dbIndex := flag.Int("db", 0, "Redis database index")
name := flag.String("name", "default", "Config name")
runCommand := flag.String("run", "", "Command to run")
remove := flag.String("remove", "", "Config var to remove")
add := flag.String("add", "", "Config var to add")
flag.Parse()
if *version {
printVersion()
} else {
client := redis.New(*netaddr, *dbIndex, "")
key := fmt.Sprintf("redis-env:%s", *name)
fmt.Println(key)
if len(*runCommand) > 0 {
run(client, key, *runCommand)
} else if len(*remove) > 0 {
removeConfig(client, key, *remove)
} else if len(*add) > 0 {
addConfig(client, key, *add)
} else if *list {
listConfig(client, key)
}
}
}
开发者ID:brynary,项目名称:redis-env,代码行数:29,代码来源:redis-env.go
示例17: main
func main() {
search := flag.String("s", "", "search issues")
create := flag.Bool("C", false, "create issue")
comment := flag.Bool("c", false, "show comments")
flag.Usage = func() {
fmt.Fprint(os.Stderr, "Usage: goissue [-c ID | -s WORD]\n")
flag.PrintDefaults()
}
flag.Parse()
if flag.NArg() > 1 {
flag.Usage()
os.Exit(1)
}
config := getConfig()
auth := authLogin(config)
if *create {
createIssue(auth)
} else if len(*search) > 0 {
searchIssues(auth, *search)
} else if flag.NArg() == 0 {
showIssues(auth)
} else {
for i := 0; i < flag.NArg(); i++ {
showIssue(auth, flag.Arg(i))
if *comment {
showComments(auth, flag.Arg(i))
}
}
}
}
开发者ID:andradeandrey,项目名称:goissue,代码行数:32,代码来源:main.go
示例18: main
func main() {
cbServ := flag.String("couchbase", "http://localhost:8091/",
"URL to couchbase")
cbBucket := flag.String("bucket", "default", "couchbase bucket")
includeExt := flag.Bool("includeExt", false, "include file extension in document ID")
verbose := flag.Bool("v", false, "verbose output")
flag.Parse()
b, err := couchbase.GetBucket(*cbServ, "default", *cbBucket)
maybeFatal(err, "Error connecting to couchbase: %v\n", err)
for _, filename := range flag.Args() {
key := pathToID(filename, *includeExt)
bytes, err := ioutil.ReadFile(filename)
maybeFatal(err, "Error reading file contents: %v\n", err)
b.SetRaw(key, 0, bytes)
if *verbose {
fmt.Printf("Loaded %s to key %s\n", filename, key)
}
}
if *verbose {
fmt.Printf("Loaded %d documents into bucket %s\n", len(flag.Args()), *cbBucket)
}
}
开发者ID:jchris,项目名称:indexing,代码行数:25,代码来源:loadfile.go
示例19: main
func main() {
var (
listDevices = flag.Bool("list", false, "list all devices listened by evdev")
printMode = flag.Bool("print", false, "print pressed keys")
quietMode = flag.Bool("quiet", false, "be silent")
deviceMatch = flag.String("match", "keyboard", "string used to match keyboard device")
keysymFirst = flag.String("first", "LEFTSHIFT", "key used for switcing on first xkb group")
keysymSecond = flag.String("second", "RIGHTSHIFT", "key used for switcing on second xkb group")
)
flag.Parse()
terminate := make(chan os.Signal)
signal.Notify(terminate, os.Interrupt)
if *listDevices {
for devicePath, device := range getInputDevices() {
fmt.Printf("[%s] %s\n", devicePath, device.Name)
}
} else {
keyFirst, err := getKeyCode(*keysymFirst)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
keySecond, err := getKeyCode(*keysymSecond)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
go listenKeyboards(keyFirst, keySecond, *printMode, *quietMode, *deviceMatch)
<-terminate
}
}
开发者ID:postfix,项目名称:shift-shift,代码行数:35,代码来源:shift-shift.go
示例20: ParseFlag
func ParseFlag() {
FlagDebugMode = flag.Bool("debug", false, "Enable debug mode")
FlagLogToStdout = flag.Bool("stdout", false, "Print log to stdout")
FlagStandalone = flag.Bool("standalone", false, "Standalone mode, skipping reg with tutum")
FlagSkipNatTunnel = flag.Bool("skip-nat-tunnel", false, "Skip NAT tunnel")
FlagDockerHost = flag.String("docker-host", "", "Override 'DockerHost'")
FlagDockerOpts = flag.String("docker-opts", "", "Add additional flags to run docker daemon")
FlagTutumHost = flag.String("tutum-host", "", "Override 'TutumHost'")
FlagTutumToken = flag.String("tutum-token", "", "Override 'TutumToken'")
FlagTutumUUID = flag.String("tutum-uuid", "", "Override 'TutumUUID'")
FlagNgrokToken = flag.String("ngrok-token", "", "ngrok token for NAT tunneling")
FlagNgrokHost = flag.String("ngrok-host", "", "ngrok host for NAT tunneling")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
flag.PrintDefaults()
fmt.Fprint(os.Stderr, " set: Set items in the config file and exit, supported items\n",
" CertCommonName=\"xxx\"\n",
" DockerHost=\"xxx\"\n",
" TutumHost=\"xxx\"\n",
" TutumToken=\"xxx\"\n",
" TutumUUID=\"xxx\"\n",
" DockerOpts=\"xxx\"\n")
}
flag.Parse()
if *FlagNgrokHost != "" {
NgrokHost = *FlagNgrokHost
}
}
开发者ID:CloudSide,项目名称:tutum-agent,代码行数:30,代码来源:config.go
注:本文中的flag.Bool函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论