Пример #1
0
func main() {
	// Parse the command line flags.
	hexPtr := flag.String("hex", "", "a hex value to convert to RGB")
	flag.Var(&rgbflag, "rgb", "an RGB value to convert to hex")
	flag.Parse()

	// If neither flag is provided, print usage and exit.
	if flag.NFlag() == 0 || flag.NFlag() == 2 {
		fmt.Println("Usage: rgbhex [-hex=ABCDEF | -rgb=123,234,100]")
		os.Exit(1)
	}

	if *hexPtr != "" {
		// Convert the provided hex value into an integer.
		hexVal, err := strconv.ParseInt(*hexPtr, 16, 32)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		fmt.Println(HexToRGB(hexVal))
	} else {
		// Convert an RGB value to hex.
		fmt.Println(RGBToHex(&rgbflag))
	}
}
Пример #2
0
func main() {
	// Arguments
	fileName := flag.String("c", "config.json", "config file")
	debug := flag.Bool("d", false, "debug mode")
	vers := flag.Bool("v", false, "version")
	flag.Parse()
	// Version
	if *vers {
		fmt.Fprintln(os.Stdout, version.Version)
		os.Exit(1)
	}
	// Logging
	log.SetName("banshee")
	if *debug {
		log.SetLevel(log.DEBUG)
	}
	log.Debug("using %s, max %d cpu", runtime.Version(), runtime.GOMAXPROCS(-1))
	// Config
	cfg := config.New()
	if flag.NFlag() == 0 || (flag.NFlag() == 1 && *debug == true) {
		log.Warn("no config file specified, using default..")
	} else {
		err := cfg.UpdateWithJSONFile(*fileName)
		if err != nil {
			log.Fatal("failed to load %s, %s", *fileName, err)
		}
	}
	// Storage
	options := &storage.Options{
		NumGrid: cfg.Period[0],
		GridLen: cfg.Period[1],
	}
	db, err := storage.Open(cfg.Storage.Path, options)
	if err != nil {
		log.Fatal("failed to open %s: %v", cfg.Storage.Path, err)
	}
	// Cleaner
	cleaner := cleaner.New(db, cfg.Period[0]*cfg.Period[1])
	go cleaner.Start()
	// Filter
	filter := filter.New()
	filter.Init(db)
	// Alerter
	alerter := alerter.New(cfg, db, filter)
	alerter.Start()
	// Webapp
	go webapp.Start(cfg, db)
	// Detector
	detector := detector.New(cfg, db, filter)
	detector.Out(alerter.In)
	detector.Start()
}
Пример #3
0
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, usage)
		fmt.Fprintln(os.Stderr, "Flags:")
		flag.PrintDefaults()
		os.Exit(2)
	}

	flag.Parse()
	if (flag.NFlag() == 0 && flag.NArg() != 2) || (flag.NFlag() == 1 && flag.NArg() > 1) {
		flag.Usage()
	}

	addr := flag.Arg(0)
	if !strings.Contains(addr, ":") {
		addr = ":" + addr
	}

	// Server mode
	if *listen {
		l, err := net.Listen("tcp", addr)
		if err != nil {
			log.Fatal(err)
		}
		defer l.Close()

		log.Fatal(Serve(l))
	}

	// Client mode
	conn, err := Dial(addr)
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()

	buf := []byte(flag.Arg(1))
	if _, err := conn.Write(buf); err != nil {
		log.Fatal(err)
	}

	n, err := conn.Read(buf)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("%s\n", buf[:n])
}
Пример #4
0
func main() {
	defer glog.Flush()

	if flag.NFlag() == 0 {
		flag.PrintDefaults()
		return
	}
	if pv {
		printVersion()
		return
	}

	if len(listenArgs) == 0 {
		glog.Fatalln("no listen addr")
	}

	var wg sync.WaitGroup
	for _, args := range listenArgs {
		wg.Add(1)
		go func(arg Args) {
			defer wg.Done()
			listenAndServe(arg)
		}(args)
	}
	wg.Wait()
}
Пример #5
0
func main() {
	flag.Parse()
	isPublic := !*gistPrivateFlag

	// if nothing was given write message
	if (flag.NFlag() == 0) && (len(flag.Args()) == 0) {
		fmt.Println("No arguments or files given!")
		fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
		flag.PrintDefaults()
		os.Exit(2)
	}

	token := Configuration.GetToken()

	if *listGistsFlag != "" {
		username := *listGistsFlag
		url := baseUrl + "users/" + username + "/gists"
		Gist.List(url)
	} else if *deleteGistFlag != "" {
		Gist.Delete(baseUrl, token, *deleteGistFlag)
	} else if *downloadGistFlag != "" {
		Gist.Download(baseUrl, token, *downloadGistFlag)
	} else {
		filesName := flag.Args()
		if len(filesName) == 0 && *updateGistFlag == "" {
			fmt.Println("No files given!")
			os.Exit(2)
		}
		if *updateGistFlag != "" {
			Gist.Update(baseUrl, token, filesName, *updateGistFlag, *gistDescriptionFlag, *openBrowserFlag)
		} else {
			Gist.Post(baseUrl, token, isPublic, filesName, *gistDescriptionFlag, *openBrowserFlag)
		}
	}
}
Пример #6
0
func init() {
	var (
		configureFile string
		printVersion  bool
	)

	flag.StringVar(&configureFile, "C", "", "configure file")
	flag.Var(&options.ChainNodes, "F", "forward address, can make a forward chain")
	flag.Var(&options.ServeNodes, "L", "listen address, can listen on multiple ports")
	flag.BoolVar(&printVersion, "V", false, "print version")
	flag.Parse()

	if err := loadConfigureFile(configureFile); err != nil {
		glog.Fatal(err)
	}

	if glog.V(5) {
		http2.VerboseLogs = true
	}

	if flag.NFlag() == 0 {
		flag.PrintDefaults()
		return
	}

	if printVersion {
		fmt.Fprintf(os.Stderr, "GOST %s (%s)\n", gost.Version, runtime.Version())
		return
	}
}
Пример #7
0
func main() {
	configFile := flag.String("config", "logstreamer.toml", "Heka Logstreamer configuration file")

	flag.Parse()

	if flag.NFlag() == 0 {
		flag.PrintDefaults()
		os.Exit(0)
	}

	fconfig := make(FileConfig)
	if _, err := toml.DecodeFile(*configFile, &fconfig); err != nil {
		log.Printf("Error decoding config file: %s", err)
		return
	}

	// Filter out logstream inputs
	inputs := make(map[string]toml.Primitive)
	for name, prim := range fconfig {
		basic := new(Basic)
		if name == "LogstreamerInput" {
			inputs[name] = prim
		} else if err := toml.PrimitiveDecode(prim, &basic); err == nil {
			if basic.PluginType == "LogstreamerInput" {
				inputs[name] = prim
			}
		}
	}

	// Go through the logstreams and parse their configs
	for name, prim := range inputs {
		parseConfig(name, prim)
	}
}
Пример #8
0
func main() {

	flag.Parse()
	if flag.NFlag() < 1 {
		fmt.Fprintf(os.Stderr, "usage:%s -f <filename>\n", os.Args[0])
		fmt.Fprintf(os.Stderr, "-n  Show number lines.\n")
		os.Exit(1)
	}

	file, err := os.Open(*filename)
	if err != nil {
		log.Fatal("%s\n", err)
	}

	scanner := bufio.NewScanner(file)
	var lines int

	for scanner.Scan() {
		if *numbers {
			fmt.Fprintf(os.Stdout, "%d: %s\n", lines, scanner.Text())
			lines++
			continue
		}
		fmt.Fprintf(os.Stdout, "%s\n", scanner.Text())
	}
}
Пример #9
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	flag.Parse()
	if flag.NFlag() != 3 {
		fmt.Printf("usage: tcpip_proxy -host target_host -port target_port -listen_post=local_port\n")
		flag.PrintDefaults()
		os.Exit(1)
	}
	target := net.JoinHostPort(*host, *port)
	fmt.Printf("Start listening on port %s and forwarding data to %s\n", *listen_port, target)
	ln, err := net.Listen("tcp", ":"+*listen_port)
	if err != nil {
		fmt.Printf("Unable to start listener, %v\n", err)
		os.Exit(1)
	}
	conn_n := 1
	for {
		if conn, err := ln.Accept(); err == nil {
			go process_connection(conn, conn_n, target)
			conn_n += 1
		} else {
			fmt.Printf("Accept failed, %v\n", err)
		}
	}
}
Пример #10
0
func main() {
	flag.Parse()
	if flag.NFlag() == 0 {
		fmt.Printf("no bottle given. usage:\n")
		flag.PrintDefaults()
		os.Exit(1)
	}
	fmt.Printf("=>> Start to uninstall gecko...\n")
	out, err := exec.Command("/opt/cxoffice/bin/wine", "--bottle="+bottle, "--", WineUninstallerPath, "--list").Output()
	if err != nil {
		fmt.Printf("ERR %s\n", err.Error())
	}
	arr := strings.Split(string(out), "\n")
	var counts int = 0
	for _, v := range arr {
		if len(v) == 0 {
			continue
		}
		s := strings.Split(v, "|||")
		if strings.HasPrefix(s[1], WeWantToRemove) {
			err := exec.Command("/opt/cxoffice/bin/wine", "--bottle="+bottle, "--", WineUninstallerPath, "--remove", s[0]).Run()
			if err != nil {
				fmt.Printf("ERR %s\n", err.Error())
			} else {
				counts++
			}
			fmt.Printf("<==done.\n")
		}
	}
	fmt.Printf("<<= %d uninstalled.\n", counts)
}
Пример #11
0
func initConfig() {
	// Config parsing.
	if flag.NFlag() == 0 || (flag.NFlag() == 1 && *debug) { // Case ./program [-d]
		log.Warnf("no config specified, using default..")
	} else { // Case ./program -c filename
		err := cfg.UpdateWithYamlFile(*fileName)
		if err != nil {
			log.Fatalf("failed to load %s, %s", *fileName, err)
		}
	}
	// Config validation.
	err := cfg.Validate()
	if err != nil {
		log.Fatalf("config: %s", err)
	}
}
Пример #12
0
func main() {

	flag.Parse()

	if flag.NFlag() == 0 {
		flag.PrintDefaults()
	}

	if _, err := os.Stat(*filePath); os.IsNotExist(err) {
		//panic("File doesn't exist")
		fmt.Println("File doesn't exist")
		os.Exit(-1)
	}

	// Take all the necessary data
	appToken := os.Getenv("APP_TOKEN")
	appSecret := os.Getenv("APP_SECRET")
	accessToken := os.Getenv("ACCESS_TOKEN")
	accessSecret := os.Getenv("ACCESS_SECRET")

	// Create the client
	client, _ := copy.NewDefaultClient(appToken, appSecret, accessToken, accessSecret)
	fs := copy.NewFileService(client)
	fmt.Println(fs.UploadFile(*filePath, *uploadPath, true))
	os.Exit(0)
}
Пример #13
0
func main() {
	to := flag.String("t", "", "destination Internet mail address")
	from := flag.String("f", "", "the sender's GMail address")
	pwd := flag.String("p", "", "the sender's password")
	subject := flag.String("s", "", "subject line of email")
	msg := flag.String("m", "", "a one-line email message")
	flag.Usage = func() {
		fmt.Printf("Syntax:\n\tGSend [flags]\nwhere flags are:\n")
		flag.PrintDefaults()
	}

	fmt.Printf("GSend v 1.01 by Jim Lawless\n")

	flag.Parse()

	if flag.NFlag() != 5 {
		flag.Usage()
		return
	}

	body := "To: " + *to + "\r\nSubject: " +
		*subject + "\r\n\r\n" + *msg
	auth := smtp.PlainAuth("", *from, *pwd, "smtp.gmail.com")
	err := smtp.SendMail("smtp.gmail.com:587", auth, *from,
		[]string{*to}, []byte(body))
	if err != nil {
		log.Fatal(err)
	}
}
Пример #14
0
func main() {
	flag.Parse()

	if flagOne == "" {
		fmt.Fprintf(os.Stdout, "Usage of cody.guo ok %s:\n", os.Args[0])
		flag.PrintDefaults()
		os.Exit(1)
	}

	fmt.Println("参数数量:", flag.NFlag())
	oneFlag := flag.Lookup("one")

	fmt.Println(oneFlag.Name, oneFlag.Value)

	// fmt.Println(len(os.Args))

	if debug {
		fmt.Println("debug is on.")
	} else {
		fmt.Println("debug is off.")
	}

	fmt.Println(flagOne)

	debugFlag := flag.Lookup("d")
	fmt.Println(debugFlag.Name, debugFlag.Value)

}
Пример #15
0
func main() {
	detector := flag.Bool("detector", false, "start detector")
	// webapp := flag.Bool("webapp", false, "start webapp")
	// alerter := flag.Bool("alerter", false, "start alerter")
	fileName := flag.String("config", "", "config path")
	version := flag.Bool("version", false, "show version")
	flag.Parse()
	if *version {
		fmt.Fprintln(os.Stderr, VERSION)
		os.Exit(1)
	}
	if flag.NFlag() != 2 {
		flag.PrintDefaults()
		os.Exit(1)
	}
	cfg, err := config.NewWithJsonFile(*fileName)
	if err != nil {
		log.Fatalf("failed to read %s: %v", *fileName, err)
	}
	switch {
	case *detector:
		StartDetector(cfg.Detector)
	default:
		flag.PrintDefaults()
		os.Exit(1)
	}
}
Пример #16
0
func main() {
	// 定义一个string flag: -word, 其默认值为"foo"
	// flag.String函数返回值为指针类型
	wordPtr := flag.String("word", "foo", "intro: a string")
	numbPtr := flag.Int("num", 33, "an int")
	boolPtr := flag.Bool("fork", false, "an int")

	// 也可以使用变量
	// 定义一个flag -dada 存入svar中
	var svar string
	flag.StringVar(&svar, "dada", "dada", "a string var")

	// flag 定义完之后需要用flag.Parse()函数解析一下
	flag.Parse()

	fmt.Println("word:", *wordPtr)
	fmt.Println("num:", *numbPtr)
	fmt.Println("fork:", *boolPtr)
	fmt.Println("svar:", svar)
	fmt.Println("tail:", flag.Args())

	// 返回flag的个数
	fmt.Println("NFlag: ", flag.NFlag())
	// 去除flag之外的其他参数的个数
	fmt.Println("NArg: ", flag.NArg())

	if flag.NArg() > 0 {
		fmt.Println("args2:", flag.Args()[0])
	}

}
Пример #17
0
func main() {
	defer glog.Flush()

	if flag.NFlag() == 0 {
		flag.PrintDefaults()
		return
	}
	if pv {
		fmt.Fprintln(os.Stderr, "gost", Version)
		return
	}

	listenArgs = parseArgs(listenAddr)
	forwardArgs = parseArgs(forwardAddr)

	if len(listenArgs) == 0 {
		glog.Exitln("no listen addr")
	}

	var wg sync.WaitGroup
	for _, args := range listenArgs {
		wg.Add(1)
		go func(arg Args) {
			defer wg.Done()
			listenAndServe(arg)
		}(args)
	}
	wg.Wait()
}
Пример #18
0
func main() {
	n := new(counter)
	t := new(counter)

	flag.Parse()
	if flag.NFlag() == 0 {
		*lflag = true
		*wflag = true
		*cflag = true
	}

	if flag.NArg() == 0 {
		count(n, os.Stdin)
		report(n, "")
	}
	for i := 0; i < flag.NArg(); i++ {
		f, err := os.Open(flag.Arg(i))
		defer f.Close()
		if err != nil {
			fmt.Fprintf(os.Stderr, "wc: can't open %s: error %s\n", flag.Arg(i), err)
			os.Exit(1)
		}
		count(n, f)
		t.lines += n.lines
		t.words += n.words
		t.chars += n.chars
		t.errors += n.errors
		t.bytes += n.bytes
		report(n, flag.Arg(i))
	}
	if flag.NArg() > 1 {
		report(t, "total")
	}
}
Пример #19
0
func main() {
	help := flag.Bool("help", false, help_text)
	version := flag.Bool("version", false, version_text)
	flag.Parse()

	if *help {
		fmt.Println(help)
		os.Exit(0)
	}

	if *version {
		fmt.Println(version_text)
		os.Exit(0)
	}

	if flag.NArg() > 0 {
		fmt.Println(help)
		os.Exit(0)
	}

	if flag.NArg() == 0 && flag.NFlag() == 0 {

		var username string

		err := GetCurrentUser(&username)

		if err != nil {
			fmt.Fprintln(os.Stderr, err)
		}

		fmt.Println(username)

	}

}
Пример #20
0
func main() {
	defer glog.Flush()

	if flag.NFlag() == 0 {
		flag.PrintDefaults()
		return
	}
	if pv {
		fmt.Println("gost", version, "git:", gitRev)
		return
	}

	listenArgs = parseArgs(listenAddr)
	forwardArgs = parseArgs(forwardAddr)

	if len(listenArgs) == 0 {
		glog.Exitln("no listen addr")
	}
	glog.Infof("gost %s(git: %s) started", version, gitRev)

	var wg sync.WaitGroup
	for _, args := range listenArgs {
		wg.Add(1)
		go func(arg Args) {
			defer wg.Done()
			listenAndServe(arg)
		}(args)
	}
	wg.Wait()
}
Пример #21
0
func main() {
	flag.Usage = usage
	flag.Parse()

	if flag.NFlag() == 0 {
		flag.Usage()
	}

	util.PrintDebug("Requesting evaluation...")
	code, _ := ioutil.ReadAll(os.Stdin)
	e := evaluate.Evaluation{
		Language: *language,
		Code:     string(code),
	}

	result, statusCode := evaluate.Evaluate(*server, e)

	if statusCode != 200 {
		util.PrintFatal(fmt.Sprintf("HTTP Code %d", statusCode))
	} else {
		if result.CompilationResult != nil {
			fmt.Println("---------- Compilation ----------")
			printResult(*result.CompilationResult)
			fmt.Println("----------  Execution  ----------")
		}
		printResult(result)
		os.Exit(result.Exitcode)
	}
}
Пример #22
0
func main() {
	flag.StringVar(&facebookUserID, "id", "", "facebook user id")
	flag.StringVar(&facebookToken, "token", "", "access token")
	flag.Parse()

	if flag.NArg() == flag.NFlag() {
		fmt.Fprintf(os.Stderr, "Error: all flags are required. Run with -help for options.\n")
		os.Exit(1)
	}

	tinderClient = tinder.Init(facebookUserID, facebookToken)
	if err := tinderClient.Auth(); err != nil {
		fmt.Fprintln(os.Stderr, "Could not authenticate: ", err.Error())
		os.Exit(1)
	}

	updateGUIChan = make(chan struct{})

	go pollTinder(updateGUIChan, tinderClient, &profile)
	go updateGUI(updateGUIChan)

	if err := runGUI(); err != nil {
		fmt.Fprintf(os.Stderr, err.Error())
	}
}
Пример #23
0
func main() {
	flag.Var(&patternVar, "pattern", "which add pattern")

	flag.Parse()

	patterns := []string{
		".DS_Store",
		".DS_Store?",
		"._*",
		".Spotlight-V100",
		".Trashes",
		"ehthumbs.db",
		"Thumbs.db",
	}

	if flag.NFlag() > 0 {
		for i := 0; i < len(patternVar); i++ {
			patterns = append(patterns, patternVar[i])
		}
	}

	if len(flag.Args()) == 0 {
		clean("./", patterns)
	} else {
		for _, args := range flag.Args() {
			clean(args, patterns)
		}
	}
}
Пример #24
0
func main() {

	flag.Parse()

	if *helpFlag {
		fmt.Println(help)
		os.Exit(0)
	}

	if flag.NArg() > 0 {
		fmt.Println(help)
		os.Exit(0)
	}

	if flag.NArg() == 0 && flag.NFlag() == 0 {

		var username string

		err := GetCurrentUser(&username)

		if err != nil {
			fmt.Fprintln(os.Stderr, err)
		}

		fmt.Println(username)

	}

}
Пример #25
0
func handle_flags(u *uroot.Utsname) string {

	flag.Parse()
	info := make([]string, 0, 6)

	if *all || flag.NFlag() == 0 {
		info = append(info, u.Sysname, u.Nodename, u.Release, u.Version, u.Machine, u.Domainname)
		goto end
	}
	if *kernel {
		info = append(info, u.Sysname)
	}
	if *node {
		info = append(info, u.Nodename)
	}
	if *release {
		info = append(info, u.Release)
	}
	if *version {
		info = append(info, u.Version)
	}
	if *machine {
		info = append(info, u.Machine)
	}
	if *domain {
		info = append(info, u.Domainname)
	}

end:
	return strings.Join(info, " ")
}
Пример #26
0
func main() {
	runtime.GOMAXPROCS(2)
	// we retrieve the movie name
	movie := flag.String("movie", "James Bond", "The Name of the movie you are looking for")
	strict := flag.Bool("strict", false, "Will find the first Movie and get Detailed info on it")
	flag.Parse()

	// If nothing Given, Go F**k yourself
	if flag.NFlag() < 1 {
		Error.Println("Go F**k yourself")
		flag.PrintDefaults()
		os.Exit(1)
	}
	if *strict {
		// Open Channels
		TmdbFilm := make(chan TMDBFilm)
		go getTMDBDetails(*movie, TmdbFilm)
		Info.Printf("Will Find this movie [%s] and no one else\n", *movie)
		film := <-TmdbFilm
		Trace.Println("IMDéBé : ", film.IMDBID)
	} else {
		Info.Println(" ---- TMDB ---- ")
		searchTMDB(*movie)
		Info.Println("--------------------------------------------------------------------------------")
		Info.Println(" ---- OMDB ---- ")
		searchOMDB(*movie)
		Info.Println("--------------------------------------------------------------------------------")

	}
}
Пример #27
0
func main() {
	title := flag.String("title", "", "영화 이름")      // 명령줄 옵션을 받은 뒤 문자열로 저장
	runtime := flag.Int("runtime", 0, "상영 시간")      // 명령줄 옵션을 받은 뒤 정수로 저장
	rating := flag.Float64("rating", 0.0, "평점")     // 명령줄 옵션을 받은 뒤 실수로 저장
	release := flag.Bool("release", false, "개봉 여부") // 명령줄 옵션을 받은 뒤 불로 저장

	flag.Parse() // 명령줄 옵션의 내용을 각 자료형별로 분석

	if flag.NFlag() == 0 { // 명령줄 옵션의 개수가 0개이면
		flag.Usage() // 명령줄 옵션 기본 사용법 출력
		return
	}

	fmt.Printf(
		"영화 이름: %s\n상영 시간: %d분\n평점: %f\n",
		*title, // 포인터이므로 값을 꺼낼 때는 역참조 사용
		*runtime,
		*rating,
	) // 명령줄 옵션으로 받은 값을 출력

	if *release == true {
		fmt.Println("개봉 여부: 개봉")
	} else {
		fmt.Println("개봉 여부: 미개봉")
	}
}
func main() {
	flagVersion := flag.Bool("version", false, "Display application version.")
	flagUser := flag.String("user", "", "Atlassian HipChat ID or Email of user to update.")
	flagAuthToken := flag.String("token", "", "Atlassian HipChat API v2 authentication token.")
	flag.Parse()

	// Handle no command-line paramters
	if flag.NFlag() == 0 {
		flag.PrintDefaults()
		os.Exit(0)
	}

	// Output version
	if *flagVersion {
		fmt.Println("iTunes to Atlassian HipChat Status", Version)
		os.Exit(0)
	}

	userInformation := viewHipChatUser(*flagUser, *flagAuthToken)
	userInformation.Presence.Status = getItunesInformation()
	if userInformation.Presence.Show == "" {
		userInformation.Presence.Show = "chat"
	}
	updateHipChatUser(userInformation, *flagUser, *flagAuthToken)
}
Пример #29
0
func main() {
	flag.Usage = usage
	flag.Parse()

	// Usage information when no arguments.
	if flag.NFlag() == 0 && flag.NArg() == 0 {
		flag.Usage()
	}

	err := parseFlags()
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		fmt.Fprintln(os.Stderr, `For usage information, run "go tool cover -help"`)
		os.Exit(2)
	}

	// Generate coverage-annotated source.
	if *mode != "" {
		annotate(flag.Arg(0))
		return
	}

	// Output HTML or function coverage information.
	if *htmlOut != "" {
		err = htmlOutput(profile, *output)
	} else {
		err = funcOutput(profile, *output)
	}

	if err != nil {
		fmt.Fprintf(os.Stderr, "cover: %v\n", err)
		os.Exit(2)
	}
}
Пример #30
0
func main() {
	flag.Parse()
	if flag.NArg() == 0 && flag.NFlag() == 0 {
		usage()
		os.Exit(1)
	}

	if *helpFlag {
		fmt.Println(help)
		os.Exit(0)
	}

	if *versionFlag {
		fmt.Println(version)
		os.Exit(0)
	}

	var total time.Duration

	// coreutil's sleep says: "Given two or more arguments, pause for the amount
	// of time specified by the sum of their value"
	for i := 0; i < flag.NArg(); i++ {
		d, err := time.ParseDuration(flag.Arg(i))
		if err != nil {
			fmt.Printf("sleep: invalid time interval ‘%s’\n", flag.Arg(i))
			os.Exit(1)
		}

		total = total + d
	}

	// sleep for a total time of passed times
	time.Sleep(total)
}