Golang Bool示例

说明

golang bool示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: Golang

命名空间/包名称: flag

示例#1
文件: zkcli.go 项目: dzch/zkcli

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)
}

示例#2
文件: sum.go 项目: postfix/rshasum

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)
			}
		}
	}
}

示例#3
文件: go-ari-struct-builder.go 项目: nvisibleinc/go-ari-struct-builder

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())
	}
}

示例#4
文件: main.go 项目: Cepave/anteye

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 {}
}

示例#5
文件: main.go 项目: jravasi/go-fuse

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)
}

示例#6
文件: android_ota_manager.go 项目: sanshao27/android_ota_manager

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)
		}
	}
}

示例#7
文件: globalconf_test.go 项目: ngdinhtoan/globalconf

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)
	}
}

示例#8
文件: main.go 项目: thesyncim/go-peerflix

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)
	}
}

示例#9
文件: main.go 项目: remogatto/prettytest

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
}

示例#10
文件: mysql.go 项目: supercaracal/mackerel-agent-plugins

// 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()
}

示例#11
文件: etcd_load.go 项目: smalleni/etcd-load-generator

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")
}

示例#12
文件: main.go 项目: cst05001/studymgo

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()
	}
}

示例#13
文件: main.go 项目: instructure/straitjacket

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")
	}
}

示例#14
文件: main.go 项目: Altece/Go-Go-Gadget-Repo

/*
 * 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")
		}
	}
}

示例#15
文件: cat.go 项目: kavinderd/cat

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
}

示例#16
文件: redis-env.go 项目: brynary/redis-env

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)
		}
	}
}

示例#17
文件: main.go 项目: andradeandrey/goissue

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))
			}
		}
	}
}

示例#18
文件: loadfile.go 项目: jchris/indexing

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)
	}
}

示例#19
文件: shift-shift.go 项目: postfix/shift-shift

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
	}
}

示例#20
文件: config.go 项目: CloudSide/tutum-agent

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
	}
}

示例#21
文件: docker.go 项目: neomantra/docker

func main() {
	if docker.SelfPath() == "/sbin/init" {
		// Running in init mode
		docker.SysInit()
		return
	}
	// FIXME: Switch d and D ? (to be more sshd like)
	flDaemon := flag.Bool("d", false, "Daemon mode")
	flDebug := flag.Bool("D", false, "Debug mode")
	bridgeName := flag.String("b", "", "Attach containers to a pre-existing network bridge")
	pidfile := flag.String("p", "/var/run/docker.pid", "File containing process PID")
	flag.Parse()
	if *bridgeName != "" {
		docker.NetworkBridgeIface = *bridgeName
	} else {
		docker.NetworkBridgeIface = docker.DefaultNetworkBridge
	}
	if *flDebug {
		os.Setenv("DEBUG", "1")
	}
	docker.GIT_COMMIT = GIT_COMMIT
	if *flDaemon {
		if flag.NArg() != 0 {
			flag.Usage()
			return
		}
		if err := daemon(*pidfile); err != nil {
			log.Fatal(err)
		}
	} else {
		if err := runCommand(flag.Args()); err != nil {
			log.Fatal(err)
		}
	}
}

示例#22
文件: main.go 项目: mervin0502/kv

func main() {
	oBuckets := flag.Bool("b", false, "show FLT buckets analysis")
	oDump := flag.Bool("d", false, "send a cdbmake formatted dump to stdout even if -f and -l is empty")
	oFirst := flag.String("f", "", "first key to dump (if non empty)")
	oLast := flag.String("l", "", "last key to dump (if non empty)")
	oMax := flag.Uint("max", 10, "errors reported limit.")
	oStat := flag.Bool("s", false, "show DB stats.")
	oVerbose := flag.Bool("v", false, "verbose mode.")
	flag.Parse()

	if flag.NArg() != 1 {
		fmt.Fprintln(os.Stderr, "Need exactly one file argument")
		os.Exit(1)
	}

	if *oStat {
		*oVerbose = true
	}

	r := rep
	if !*oVerbose {
		r = null
	}

	if err := main0(flag.Arg(0), int(*oMax), r, *oStat, *oFirst, *oLast,
		*oDump, *oBuckets); err != nil {
		fmt.Fprintf(os.Stderr, "kvaudit: %v\n", err)
		os.Exit(1)
	}
}

示例#23
文件: config.go 项目: drewwells/ltc-client

func getConfig() Config {
	route := flag.String("route", "small", "The route to call on the server (small|med|large|xlarge)")
	host := flag.String("host", "localhost", "The host of the server")
	port := flag.String("port", "80", "The port of the host server")
	https := flag.Bool("https", false, "Use https as the transfer protocol.")

	apigee := flag.Bool("apigee", false, "Use an apigee request")
	configFile := flag.String("config", "config.json", "Location of config file")

	flag.Parse()

	var config Config

	if *apigee {
		file, err := ioutil.ReadFile(*configFile)
		if err != nil {
			fmt.Printf("File error: %v\n", err)
			os.Exit(1)
		}

		err = json.Unmarshal(file, &config)
		if err != nil {
			fmt.Printf("JSON error: %v\n", err)
			os.Exit(1)
		}
	}

	config.setEndpoint(*route, *host, *port, *https)
	config.UseApigee = *apigee

	return config
}

示例#24
文件: main.go 项目: ricardodani/gandalf

func main() {
	dry := flag.Bool("dry", false, "dry-run: does not start the server (for testing purpose)")
	configFile := flag.String("config", "/etc/gandalf.conf", "Gandalf configuration file")
	gVersion := flag.Bool("version", false, "Print version and exit")
	flag.Parse()
	if *gVersion {
		fmt.Printf("gandalf-webserver version %s\n", version)
		return
	}
	log.Printf("Opening config file: %s ...\n", *configFile)
	err := config.ReadAndWatchConfigFile(*configFile)
	if err != nil {
		msg := `Could not open gandalf config file at %s (%s).
  For an example, see: gandalf/etc/gandalf.conf
  Note that you can specify a different config file with the --config option -- e.g.: --config=./etc/gandalf.conf`
		log.Fatalf(msg, *configFile, err)
	}
	log.Printf("Successfully read config file: %s\n", *configFile)
	router := api.SetupRouter()
	bind, err := config.GetString("bind")
	if err != nil {
		var perr error
		bind, perr = config.GetString("webserver:port")
		if perr != nil {
			panic(err)
		}
	}
	if !*dry {
		log.Fatal(http.ListenAndServe(bind, router))
	}
}

示例#25
文件: main.go 项目: CloudLife/go-fuse

func main() {
	// Scans the arg list and sets up flags
	debug := flag.Bool("debug", false, "print debugging messages.")
	latencies := flag.Bool("latencies", false, "record operation latencies.")

	flag.Parse()
	if flag.NArg() < 2 {
		fmt.Fprintf(os.Stderr, "usage: %s MOUNTPOINT ZIP-FILE\n", os.Args[0])
		os.Exit(2)
	}

	var fs fuse.NodeFileSystem
	fs, err := zipfs.NewArchiveFileSystem(flag.Arg(1))
	if err != nil {
		fmt.Fprintf(os.Stderr, "NewArchiveFileSystem failed: %v\n", err)
		os.Exit(1)
	}

	state, _, err := fuse.MountNodeFileSystem(flag.Arg(0), fs, nil)
	if err != nil {
		fmt.Printf("Mount fail: %v\n", err)
		os.Exit(1)
	}

	state.SetRecordStatistics(*latencies)
	state.Debug = *debug
	state.Loop()
}

示例#26
文件: config.go 项目: The-Cloud-Source/opentsp

func Load(tsdbChan chan<- *tsdb.Point) {
	var (
		filePath  = flag.String("f", "/etc/collect-statse/config", "configuration file")
		debugMode = flag.Bool("v", false, "verbose mode")
		testMode  = flag.Bool("t", false, "configuration test")
	)
	flag.Parse()
	log.SetFlags(0)
	if flag.NArg() != 0 {
		flag.Usage()
		os.Exit(1)
	}
	if *debugMode {
		w := os.Stderr
		xconfig.Debug = log.New(w, "debug: config: ", 0)
		statse.Debug = log.New(w, "debug: statse: ", 0)
		forwarder.Debug = log.New(w, "debug: forwarder: ", 0)
		filter.Debug = log.New(w, "debug: forwarder/filter: ", 0)
		aggregator.Debug = log.New(w, "debug: aggregator: ", 0)
	}
	config := new(Config)
	xconfig.Load(config, *filePath, "collect-statse?host={{.Hostname}}")
	if *testMode {
		config.Dump(os.Stdout)
		os.Exit(0)
	}
	Loaded = config
	aggregator.Init(tsdbChan)
	log.Printf("start pid=%d", os.Getpid())
}

示例#27
文件: mutegenerate.go 项目: JonathanLogan/mute

func main() {
	output := flag.String("o", "", "write generated code to file")
	release := flag.Bool("r", false, "write output for release (server config format)")
	test := flag.Bool("t", false, "just exit with status code 0 (test if binary exists)")
	flag.Parse()
	if flag.NArg() != 0 {
		usage()
	}
	if *test {
		return
	}
	if os.Getenv("GO15VENDOREXPERIMENT") != "1" {
		fatal(errors.New("environment variable GO15VENDOREXPERIMENT not set to 1"))
	}
	commit, date, err := git.GetHead("", os.Stderr)
	if err != nil {
		fatal(err)
	}
	outfp := os.Stdout
	if *output != "" {
		if !commitChanged(*output, commit) {
			// nothing to write
			return
		}
		outfp, err = os.Create(*output)
		if err != nil {
			fatal(err)
		}
	}
	printCode(outfp, *release, commit, date)
}

示例#28
文件: htlc.go 项目: yatuhashi/SSLGOMI

func main() {
	fmt.Println("Please wait....")
	URL := flag.String("i", "https://127.0.0.1/", "dst server URL")
	num := flag.Int("n", 1, "process num")
	loop := flag.Bool("l", false, "loop flag")
	ecdh := flag.Bool("e", false, "ecdh flag")
	show := flag.Bool("s", false, "show body flag")
	flag.Parse()
	result := make(chan int)
	//通信結果を受け取るためのプロセス
	go recieving(result, *loop, *num)

	t := time.Now()
	for i := 0; i < *num; i++ { //通信プロセスの作成
		go connect(*URL, i, *loop, *show, *ecdh, result)
	}
	f := time.Now()
	//通信プロセスの作成時間
	fmt.Println("Create process time: ", f.Sub(t))
	//現在動いてるプロセス数
	fmt.Println("Current Process num: ", runtime.NumGoroutine())
	//mainプロセスを待機させておく
	time.Sleep(3 * time.Second) //プロセス作成時間分待機
	//プロセスが残ってるうちは待機
	for runtime.NumGoroutine() > 4 || *loop {
		time.Sleep(1 * time.Second)
	}
	//終了時のプロセス数
	fmt.Println("Current Process num: ", runtime.NumGoroutine())
}

示例#29
文件: docker.go 项目: r0b0ticus/docker

func main() {
	if docker.SelfPath() == "/sbin/init" {
		// Running in init mode
		docker.SysInit()
		return
	}
	// FIXME: Switch d and D ? (to be more sshd like)
	flDaemon := flag.Bool("d", false, "Daemon mode")
	flDebug := flag.Bool("D", false, "Debug mode")
	flag.Parse()
	if *flDebug {
		os.Setenv("DEBUG", "1")
	}
	docker.GIT_COMMIT = GIT_COMMIT
	if *flDaemon {
		if flag.NArg() != 0 {
			flag.Usage()
			return
		}
		if err := daemon(); err != nil {
			log.Fatal(err)
		}
	} else {
		if err := runCommand(flag.Args()); err != nil {
			log.Fatal(err)
		}
	}
}

示例#30
文件: main.go 项目: ZeaLoVe/query

func main() {
	cfg := flag.String("c", "cfg.json", "specify config file")
	version := flag.Bool("v", false, "show version")
	versionGit := flag.Bool("vg", false, "show version and git commit log")
	flag.Parse()

	if *version {
		fmt.Println(g.VERSION)
		os.Exit(0)
	}
	if *versionGit {
		fmt.Println(g.VERSION, g.COMMIT)
		os.Exit(0)
	}

	// config
	g.ParseConfig(*cfg)
	// proc
	proc.Start()

	// graph
	graph.Start()

	// http
	http.Start()

	select {}
}

展开阅读全文