예제 #1
0
func main() {
	goopt.Author = Author
	goopt.Version = Version
	goopt.Summary = Summary
	goopt.Parse(nil)

	if len(goopt.Args) == 0 {
		println(goopt.Usage())
		return
	}

	if *concurrency > *reqs {
		fmt.Printf("You can't have concurrency higher than number of requests\n")
		return
	}

	url, ip, err := getURL(goopt.Args[0])
	if err != nil {
		fmt.Printf("url is invalid: %s\n", err)
		return
	}

	runtime.GOMAXPROCS(*cpus)

	fmt.Printf("Statistics for requests to %s\n", goopt.Args[0])
	results, total := start(url, ip, *reqs, *concurrency)
	printStats(results, total)
}
예제 #2
0
func main() {
	goopt.Version = Version
	goopt.Summary = Summary

	goopt.Parse(nil)

	if *showSummary && *doWatch {
		errhandle(fmt.Errorf("--summary and --watch do not mix together well"))
	}

	if *showVersion {
		out("gostatic %s\n", goopt.Version)
		return
	}

	if *showProcessors {
		ProcessorSummary()
		return
	}

	if len(goopt.Args) == 0 {
		println(goopt.Usage())
		return
	}

	config, err := NewSiteConfig(goopt.Args[0])
	errhandle(err)

	if *showConfig {
		x, err := json.MarshalIndent(config, "", "  ")
		errhandle(err)
		println(string(x))
		return
	}

	site := NewSite(config)
	if *showSummary {
		site.Summary()
	} else {
		site.Render()
	}

	if *doWatch {
		StartWatcher(config)
		out("Starting server at *:%s...\n", *port)

		fs := http.FileServer(http.Dir(config.Output))
		http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
			w.Header().Set("Cache-Control", "no-store")
			fs.ServeHTTP(w, r)
		})

		err := http.ListenAndServe(":"+*port, nil)
		errhandle(err)
	}
}
예제 #3
0
파일: main.go 프로젝트: serussell/kgc
func main() {

	goopt.Version = fmt.Sprintf("%d.%d", VER_MAJOR, VER_MINOR)
	goopt.Summary = PROG_NAME
	goopt.Parse(nil)

	if *ver {
		fmt.Printf("\n%s version %d.%d", PROG_NAME, VER_MAJOR, VER_MINOR)
		fmt.Printf("\nCopyright (c) 2011 Chanwit Kaewkasi / SUT\n\n")
		return
	}

	var filename string = ""
	if len(goopt.Args) == 1 {
		filename = goopt.Args[0]
	} else {
		fmt.Print(goopt.Usage())
		return
	}

	fset := token.NewFileSet()
	astf, err := parser.ParseFile(fset, filename, nil, 0)
	if err == nil {
		v := NewVisitor(astf)
		Walk(v, astf)
		tempfile, err := os.OpenFile(filename+"k", os.O_WRONLY|os.O_CREATE, 0665)
		if err == nil {
			printer.Fprint(tempfile, fset, astf)
			tempfile.Close()
			newArgs := make([]string, len(os.Args))
			copy(newArgs, os.Args)
			for i, v := range newArgs {
				if v == filename {
					newArgs[i] = filename + "k"
				}
			}
			gc := "8g"
			switch os.Getenv("GOARCH") {
			case "386":
				gc = "8g"
			case "amd64":
				gc = "6g"
			case "arm":
				gc = "5g"
			}
			newArgs[0] = os.Getenv("GOROOT") + "/bin/" + gc
			StdExecve(newArgs, true)
			os.Remove(filename + "k")
		}
	} else {
		fmt.Printf("%s\n", err)
	}
}
예제 #4
0
func main() {
	goopt.Author = Author
	goopt.Version = Version
	goopt.Summary = Summary
	goopt.Usage = func() string {
		return fmt.Sprintf("Usage of goreplace %s:\n\t", Version) +
			goopt.Summary + "\n" + goopt.Help()
	}

	var noIgnores bool
	for _, item := range os.Args[1:] {
		if item == "-I" || item == "--no-autoignore" {
			noIgnores = true
		}
	}

	cwd, _ := os.Getwd()
	ignorer := NewIgnorer(cwd, noIgnores)
	goopt.Summary += fmt.Sprintf("\n%s", ignorer)

	goopt.Parse(nil)


	if *showVersion {
		fmt.Printf("goreplace %s\n", goopt.Version)
		return
	}

	ignorer.Append(*ignoreFiles)

	if len(goopt.Args) == 0 {
		println(goopt.Usage())
		return
	}

	arg := goopt.Args[0]
	if *plaintext {
		arg = escapeRegex(arg)
	}
	if *ignoreCase {
		arg = "(?i:" + arg + ")"
	}

	pattern, err := regexp.Compile(arg)
	errhandle(err, true, "")

	if pattern.Match([]byte("")) {
		errhandle(errors.New("Your pattern matches empty string"), true, "")
	}

	searchFiles(pattern, ignorer)
}
예제 #5
0
파일: erg.go 프로젝트: xaviershay/erg
func main() {
	if envHost := os.Getenv("RANGE_HOST"); len(envHost) > 0 {
		*host = envHost
	}

	if envSsl := os.Getenv("RANGE_SSL"); len(envSsl) > 0 {
		*ssl = true
	}

	if envPort := os.Getenv("RANGE_PORT"); len(envPort) > 0 {
		x, err := strconv.Atoi(envPort)
		if err == nil {
			*port = x
		} else {
			fmt.Fprintf(os.Stderr, "Invalid port in RANGE_PORT: %s\n", envPort)
			os.Exit(1)
		}
	}
	goopt.Parse(nil)

	var query string
	switch len(goopt.Args) {
	case 1:
		query = goopt.Args[0]
	default:
		fmt.Fprintln(os.Stderr, goopt.Usage())
		os.Exit(1)
	}

	var e *erg.Erg

	if *ssl {
		e = erg.NewWithSsl(*host, *port)
	} else {
		e = erg.New(*host, *port)
	}

	result, err := e.Expand(query)
	if err != nil {
		fmt.Println("Error: ", err.Error())
		os.Exit(1)
	}

	if *expand {
		for _, node := range result {
			fmt.Println(node)
		}
	} else {
		fmt.Println(e.Compress(result))
	}
}
예제 #6
0
파일: main.go 프로젝트: jshort/go-hash
func main() {
	var progname = os.Args[0][strings.LastIndex(os.Args[0], "/")+1:]

	var algorithm = goopt.StringWithLabel([]string{"-a", "--algorithm"}, algorithms[0],
		"ALG", fmt.Sprintf("Hashing algorithm: %s", algorithms))
	var version = goopt.Flag([]string{"-V", "--version"}, []string{}, "Display version", "")

	goopt.Summary = fmt.Sprintf("%s [OPTIONS] FILENAME\n\nMessage digest calculator with various hashing algorithms.\n\nArguments:\n  FILENAME                 File(s) to hash\n", progname)
	goopt.Parse(nil)

	var files []string = goopt.Args

	if *version {
		fmt.Printf("%s version %s\n", progname, Version)
		os.Exit(0)
	}

	validateAlgorithm(goopt.Usage(), *algorithm)
	valildateFiles(goopt.Usage(), files)

	calculateDigest(files, *algorithm)

	os.Exit(0)
}
예제 #7
0
func main() {
	goopt.Parse(func() []string { return nil })
	pname, err := έντομο.ProjectName()
	dieOn(err)
	fmt.Println("Project name is", pname)
	if *action == "help" {
		fmt.Println(goopt.Usage())
		os.Exit(0)
	}
	switch *action {
	case "new-issue":
		if *message == "" {
			fmt.Println("What is the problem?")
			bugtext, err := Edit("ENTER BUG REPORT HERE")
			dieOn(err)
			*message = bugtext
		}
		_, err := bug.New(*message)
		dieOn(err)
	case "comment":
		if *bugid == "" {
			fmt.Print("Which bug? ")
			inp, e := bufio.NewReaderSize(os.Stdin, 1)
			dieOn(e)
			*bugid, err = inp.ReadString('\n')
			if len(*bugid) > 0 {
				*bugid = (*bugid)[:len(*bugid)-1]
			}
		}
		b, err := έντομο.LookupBug(*bugid)
		dieOn(err)
		fmt.Print("What do you want to say? ")
		bugtext, err := Edit("ENTER COMMENT HERE")
		dieOn(err)
		b.AddComment(bugtext)
	default:
		fmt.Println("I should do", *action)
		os.Exit(1)
	}
}
예제 #8
0
func badUsage() {
	fmt.Println(goopt.Usage())
	os.Exit(1)
}
예제 #9
0
파일: core.go 프로젝트: uiri/coreutils
func PrintUsage() {
	fmt.Fprintf(os.Stderr, goopt.Usage())
	os.Exit(1)
}