Beispiel #1
0
func main() {
	goopt.Suite = "XQZ coreutils"
	goopt.Author = "Aaron Muir Hamilton"
	goopt.Version = "Sleep v0.1"
	goopt.Summary = "Waits for a duration before continuing."
	goopt.Usage = func() string {
		return fmt.Sprintf("Usage of %s:\n\t   %s STRING\n\tor %s OPTION\n", os.Args[0], os.Args[0], os.Args[0]) +
			goopt.Summary + "\n\n" + goopt.Help()
	}
	goopt.Description = func() string {
		return goopt.Summary + "\n\nUnless an option is passed to it."
	}
	goopt.NoArg([]string{"-v", "--version"}, "outputs version information and exits", version)
	goopt.Parse(nil)
	duration, err := time.ParseDuration(os.Args[1])
	if err != nil {
		number, interr := strconv.ParseFloat(os.Args[1], 64)
		if interr != nil {
			fmt.Println(err)
			os.Exit(0)
		}
		duration := time.Duration(number) * time.Second
		time.Sleep(duration)
		os.Exit(0)
	}
	time.Sleep(duration)
}
Beispiel #2
0
func cliSetup() *cliOptions {

	options := newCliOptions()

	var httpVerb = goopt.StringWithLabel([]string{"-X", "--command"}, options.httpVerb,
		"COMMAND", fmt.Sprintf("HTTP verb for request: %s", HttpVerbs))
	var httpHeaders = goopt.Strings([]string{"-H", "--header"},
		"KEY:VALUE", "Custom HTTP Headers to be sent with request (can pass multiple times)")
	var postData = goopt.StringWithLabel([]string{"-d", "--data"}, options.postData,
		"DATA", "HTTP Data for POST")
	var timeOut = goopt.IntWithLabel([]string{"-t", "--timeout"}, options.timeout,
		"TIMEOUT", "Timeout in seconds for request")
	var shouldRedirect = goopt.Flag([]string{"-r", "--redirect"}, []string{}, "Follow redirects", "")
	var isVerbose = goopt.Flag([]string{"-v", "--verbose"}, []string{}, "Verbose output", "")
	var hasColor = goopt.Flag([]string{"-c", "--color"}, []string{}, "Colored output", "")
	var isInsecureSSL = goopt.Flag([]string{"-k", "--insecure"}, []string{}, "Allow insecure https connections", "")

	goopt.Summary = "Golang based http client program"
	goopt.Parse(nil)

	options.httpVerb = *httpVerb
	options.httpHeaders = *httpHeaders
	options.postData = *postData
	options.timeout = *timeOut
	options.verbose = *isVerbose
	options.redirect = *shouldRedirect
	options.color = *hasColor
	options.sslInsecure = *isInsecureSSL
	options.arguments = goopt.Args

	exitWithMessageIfNonZero(validateOptions(options))
	exitWithMessageIfNonZero(validateArguments(options))

	return options
}
Beispiel #3
0
func main() {
	goopt.Suite = "XQZ coreutils"
	goopt.Author = "William Pearson"
	goopt.Version = "Unlink v0.1"
	goopt.Summary = "Uses unlink to remove FILE"
	goopt.Usage = func() string {
		return fmt.Sprintf("Usage:\t%s FILE\n or:\t%s OPTION\n", os.Args[0], os.Args[0]) + goopt.Summary + "\n\n" + goopt.Help()
	}
	goopt.Description = func() string {
		return goopt.Summary + "\n\nUnless an option is passed to it."
	}
	goopt.NoArg([]string{"-v", "--version"}, "outputs version information and exits", version)
	goopt.Parse(nil)
	switch {
	case len(os.Args) == 1:
		fmt.Println("Missing filenames")
	case len(os.Args) > 2:
		fmt.Println("Too many filenames")
	}
	if len(os.Args) != 2 {
		os.Exit(1)
	}
	file := os.Args[1]
	if err := syscall.Unlink(file); err != nil {
		fmt.Println("Encountered an error during unlinking: %v", err)
		os.Exit(1)
	}
	return
}
Beispiel #4
0
func main() {
	goopt.Description = func() string {
		return "Example program for using the goopt flag library."
	}
	goopt.Version = "1.0"
	goopt.Summary = "goopt demonstration program"
	goopt.Parse(nil)
	defer fmt.Print("\033[0m") // defer resetting the terminal to default colors
	switch *color {
	case "default":
	case "red":
		fmt.Print("\033[31m")
	case "green":
		fmt.Print("\033[32m")
	case "blue":
		fmt.Print("\033[34m")
	default:
		panic("Unrecognized color!") // this should never happen!
	}
	log("I have now set the color to", *color, ".")
	for i := 0; i < *repetitions; i++ {
		fmt.Println("Greetings,", *username)
		log("You have", *repetitions, "children.")
		for _, child := range *children {
			fmt.Println("I also greet your child, whose name is", child)
		}
	}
}
Beispiel #5
0
func main() {
	goopt.Summary = "silly test program"
	goopt.Parse(nil)
	if *amVerbose {
		fmt.Println("I am verbose.")
	}
	if *amHappy {
		fmt.Println("I am happy")
	} else {
		fmt.Println("I am unhappy")
	}
	fmt.Println("Your name is", *foo)
	fmt.Println(*bar, "... Did I scare you?")
	fmt.Println("I am going so very", *speed, "!!!")
	fmt.Print("Here is the saying:")
	for _, w := range *words {
		fmt.Print(" ", w)
	}
	fmt.Println()
	fmt.Println(*baz)
	fmt.Print("Back in my day,")
	for _, w := range goopt.Args {
		fmt.Print(" ", w)
	}
	fmt.Println()
	fmt.Printf("What's up, man%s\n", strings.Repeat("?", *width))
}
Beispiel #6
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)
}
Beispiel #7
0
func main() {

	if len(os.Args) < 2 {
		fmt.Fprintf(os.Stderr, "Usage: %s -h for help\n", os.Args[0])
		os.Exit(1)
	}

	config_file := goopt.String([]string{"-c", "--config"}, "nrpe.cfg",
		"config file to use")
	//the first option, will be the default, if the -m isnt given
	run_mode := goopt.Alternatives([]string{"-m", "--mode"},
		[]string{"foreground", "daemon", "systemd"}, "operating mode")
	goopt.Parse(nil)

	//implement different run modes..
	fmt.Println(*run_mode)
	config_obj := new(read_config.ReadConfig)
	config_obj.Init(*config_file)
	err := config_obj.ReadConfigFile()
	common.CheckError(err)
	//extract the commands command[cmd_name] = "/bin/foobar"
	config_obj.ReadCommands()
	config_obj.ReadPrivileges()
	//TODO check for errors
	//what we gonna do with the group?
	pwd := drop_privilege.Getpwnam(config_obj.Nrpe_user)
	drop_privilege.DropPrivileges(int(pwd.Uid), int(pwd.Gid))
	//we have to read it from config
	service := ":5666"
	err = setupSocket(4, service, config_obj)
	common.CheckError(err)
}
Beispiel #8
0
func main() {
	goopt.Parse(func() []string { return []string{} })

	syscall.Umask(0077) // Turn off read/write/execute priviledges for others

	if len(goopt.Args) < 1 {
		fmt.Println("You need to provide a go file argument.")
		os.Exit(1)
	}

	execname := goopt.Args[0] + ".secret"
	e := compile.Compile(execname, goopt.Args)
	if e != nil {
		fmt.Fprintln(os.Stderr, e)
		os.Exit(1)
	}
	if *outname == "FILENAME.go" {
		fmt.Fprintln(os.Stderr, "secretrun requires a -o argument!")
		os.Exit(1)
	}
	e = deps.Exec("./"+execname, *outname)
	os.Remove(execname)
	if e != nil {
		fmt.Fprintln(os.Stderr, e)
		os.Exit(1)
	}
}
Beispiel #9
0
func main() {
	goopt.Suite = "XQZ coreutils"
	goopt.Author = "William Pearson"
	goopt.Version = "Link v0.1"
	goopt.Summary = "Creates a link to FILE1 called FILE2"
	goopt.Usage = func() string {
		return fmt.Sprintf("Usage:\t%s FILE1 FILE2\n or:\t%s OPTION\n", os.Args[0], os.Args[0]) + goopt.Summary + "\n\n" + goopt.Help()
	}
	goopt.Description = func() string {
		return goopt.Summary + "\n\nUnless an option is passed to it."
	}
	goopt.NoArg([]string{"-v", "--version"}, "outputs version information and exits", version)
	goopt.Parse(nil)
	switch {
	case len(os.Args) == 1:
		fmt.Println("Missing filenames")
	case len(os.Args) == 2:
		fmt.Println("Missing filename after '%s'", os.Args[1])
	case len(os.Args) > 3:
		fmt.Println("Too many filenames")
	}
	if len(os.Args) != 3 {
		os.Exit(1)
	}
	file1 := os.Args[1]
	file2 := os.Args[2]
	if err := os.Link(file1, file2); err != nil {
		fmt.Println("Encountered an error during linking: %v", err)
		os.Exit(1)
	}
	return
}
Beispiel #10
0
func main() {
	goopt.Parse(func() []string { return nil })
	if len(goopt.Args) > 0 {
		x, err := parser.ParseFiles(myfiles, goopt.Args, 0)
		die(err)
		fmt.Fprintln(os.Stderr, "Parsed: ", *x["main"])
		die(typechecker.CheckPackage(myfiles, x["main"], nil))
		fmt.Fprintln(os.Stderr, "Checked: ", *x["main"])
		//for _,a := range x["main"].Files {
		//	die(printer.Fprint(os.Stdout, a))
		//}

		aaa := x86.StartData
		var bbb *Stack
		var cv = CompileVisitor{&aaa, make(map[string]string), bbb.New("global")}
		ast.Walk(StringVisitor(cv), x["main"])

		cv.Append(x86.StartText...)
		ast.Walk(&cv, x["main"])

		// Here we just add a crude debug library
		cv.Append(x86.Debugging...)
		ass := x86.Assembly(*cv.assembly)
		//fmt.Println(ass)
		die(elf.AssembleAndLink(goopt.Args[0][:len(goopt.Args[0])-3], []byte(ass)))
	}
}
Beispiel #11
0
func Init(summary string, description func() string, getopts func() []string ) {
	goopt.Author = "David Roundy"
	goopt.Description = description
	goopt.Summary = summary
	goopt.Version = "0.0"
	goopt.Suite = "Iolaus"
	goopt.Parse(getopts)
}
Beispiel #12
0
// Setup some flag-related options and parse said flags.
func setup() {
	goopt.Description = func() string {
		return "A dead-simple markdown conversion program."
	}
	goopt.Version = "1.0"
	goopt.Summary = "Markdown converter"
	goopt.Parse(nil)
}
Beispiel #13
0
Datei: main.go Projekt: erik/gob
func main() {
	opt.Parse(nil)

	if *showVersion {
		fmt.Printf("Gob v%s\n", GOB_VERSION)
		return
	}

	if len(opt.Args) < 1 {
		fmt.Println("Need to specify an input file")
		return
	}

	for _, name := range opt.Args {
		if len(opt.Args) > 1 {
			fmt.Printf("==== %s ====\n", name)
		}

		file, err := os.Open(name)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}

		parser := parse.NewParser(name, file)

		unit, err := parser.Parse()
		if err != nil {
			fmt.Println(err)
		}

		if err = unit.Verify(); err != nil {
			fmt.Println(err)
		}

		if *parseOnly {
			continue
		}

		var outName string = *outFile

		if outName == "" {
			outName = path.Base(name) + ".c"
		}

		if file, err = os.Create(outName); err != nil {
			fmt.Println(err)
			os.Exit(1)
		}

		var emit emit.CEmitter
		emit.Emit(file, unit)

		file.Close()
	}
}
Beispiel #14
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)
	}
}
Beispiel #15
0
func main() {
	var no_cog = goopt.Flag([]string{"-C", "--no-cog"}, []string{"-c", "--cog"},
		"skip opening in cog", "open in cog")
	var no_delete = goopt.Flag([]string{"-D", "--no-delete"}, []string{"-d", "--delete"},
		"skip deleting original zip", "delete original zip")
	goopt.Parse(nil)

	boomkat(goopt.Args[0], *no_cog, *no_delete)

}
Beispiel #16
0
func main() {

	goopt.Parse(nil)

	// IPv4 only for no real reason, could be v6 by adjusting the sizes
	// here and where it's used
	var serverAddr [4]byte

	IP := net.ParseIP(*connect)
	if IP == nil {
		log.Fatal("Unable to process IP: ", *connect)
	}

	copy(serverAddr[:], IP[12:16])

	if *listen {

		server := TFOServer{ServerAddr: serverAddr, ServerPort: *port}
		err := server.Bind()
		if err != nil {
			log.Fatalln("Failed to bind socket:", err)
		}

		// Create a new routine ("thread") and wait for connection from client
		go server.Accept()

	}

	client := TFOClient{ServerAddr: serverAddr, ServerPort: *port}

	err := client.Send()
	if err != nil {
		log.Fatalln("Failed to send to server:", err)
	}

	// Give the server a chance to receive, process the packet and print results
	time.Sleep(100 * time.Millisecond)

	success, cached, err := checkTcpMetrics(*connect)
	if err != nil {
		log.Println("ip tcp_metrics failure:", err)
	} else {
		var response string
		if success {
			response = "TFO success to IP " + *connect
		} else {
			response = "TFO failure to IP " + *connect
		}
		if len(cached) > 0 {
			response += " " + strings.Join(cached, ", ")
		}
		log.Println(response)
	}

}
Beispiel #17
0
func init() {
	//Parse options
	goopt.Parse(nil)

	// Setup goopts
	goopt.Description = func() string {
		return "Galera http Check"
	}
	goopt.Version = "0.9.2"
	goopt.Summary = "galera_http_check [-H] [-p]"

}
Beispiel #18
0
func main() {
	goopt.Author = "William Pearson"
	goopt.Version = "Rmdir"
	goopt.Summary = "Remove each DIRECTORY if it is empty"
	goopt.Usage = func() string {
		return fmt.Sprintf("Usage:\t%s [OPTION]... DIRECTORY...\n", os.Args[0]) + goopt.Summary + "\n\n" + goopt.Help()
	}
	goopt.Description = func() string {
		return goopt.Summary + "\n\nUnless --help or --version is passed."
	}
	ignorefail := goopt.Flag([]string{"--ignore-fail-on-non-empty"}, nil,
		"Ignore each failure that is from a directory not being empty", "")
	parents := goopt.Flag([]string{"-p", "--parents"}, nil, "Remove DIRECTORY and ancestors if ancestors become empty", "")
	verbose := goopt.Flag([]string{"-v", "--verbose"}, nil, "Output each directory as it is processed", "")
	goopt.NoArg([]string{"--version"}, "outputs version information and exits", coreutils.Version)
	goopt.Parse(nil)
	if len(goopt.Args) == 0 {
		coreutils.PrintUsage()
	}
	for i := range goopt.Args {
		filelisting, err := ioutil.ReadDir(goopt.Args[i])
		if err != nil {
			fmt.Fprintf(os.Stderr, "Failed to remove %s: %v\n", os.Args[i+1], err)
			defer os.Exit(1)
			continue
		}
		if !*ignorefail && len(filelisting) > 0 {
			fmt.Fprintf(os.Stderr, "Failed to remove '%s' directory is non-empty\n", goopt.Args[i])
			defer os.Exit(1)
			continue
		}
		if *verbose {
			fmt.Printf("Removing directory %s\n", goopt.Args[i])
		}
		err = os.Remove(goopt.Args[i])
		if err != nil {
			fmt.Fprintf(os.Stderr, "Failed to remove %s: %v\n", goopt.Args[i], err)
			defer os.Exit(1)
			continue
		}
		if !*parents {
			continue
		}
		dir := goopt.Args[i]
		if dir[len(dir)-1] == '/' {
			dir = filepath.Dir(dir)
		}
		if removeEmptyParents(dir, *verbose, *ignorefail) {
			defer os.Exit(1)
		}
	}
	return
}
Beispiel #19
0
func main() {
	atime = time.Now()
	mtime = time.Now()
	goopt.Author = "William Pearson"
	goopt.Version = "Touch"
	goopt.Summary = "Change access or modification time of each FILE"
	goopt.Usage = func() string {
		return fmt.Sprintf("Usage:\t%s [OPTION]... FILE...\n", os.Args[0]) +
			goopt.Summary + "\n\n" + goopt.Help()
	}
	goopt.Description = func() string {
		return goopt.Summary + "\n\nUnless --help or --version is passed."
	}
	access := goopt.Flag([]string{"-a"}, nil, "Only change access time", "")
	modify := goopt.Flag([]string{"-m"}, nil, "Only change modification time", "")
	create := goopt.Flag([]string{"-c"}, nil, "Only change modification time", "")
	Nodereference = goopt.Flag([]string{"-h", "--no-dereference"}, []string{"--derference"}, "Affect symbolic links directly instead of dereferencing them", "Dereference symbolic links before operating on them (This is default)")
	goopt.OptArg([]string{"-r", "--reference"}, "RFILE", "Use RFILE's owner and group", fromReference)
	goopt.OptArg([]string{"-t"}, "STAMP", "Use [[CC]YY]MMDDhhmm[.ss] instead of now. Note hh is interpreted as from 00 to 23", fromStamp)
	goopt.NoArg([]string{"--version"}, "outputs version information and exits", coreutils.Version)
	goopt.Parse(nil)
	coreutils.Noderef = *Nodereference
	if len(goopt.Args) == 0 {
		coreutils.PrintUsage()
	}
	if !*access && !*modify {
		*access, *modify = true, true
	}
	for i := range goopt.Args {
		if !*access {
			atime, _ = GetAtimeMtime(goopt.Args[i], *Nodereference)
		}
		if !*modify {
			_, mtime = GetAtimeMtime(goopt.Args[i], *Nodereference)
		}
		if err := os.Chtimes(goopt.Args[i], atime, mtime); err != nil {
			if os.IsNotExist(err) {
				var err error
				if !*create {
					f, err := os.Create(goopt.Args[i])
					if err == nil {
						f.Close()
					}
				}
				if err == nil {
					continue
				}
			}
			fmt.Fprintf(os.Stderr, "Error touching file '%s': %v\n", goopt.Args[i], err)
		}
	}
	return
}
Beispiel #20
0
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)
	}
}
Beispiel #21
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)
}
Beispiel #22
0
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))
	}
}
Beispiel #23
0
func main() {
	goopt.Author = "William Pearson"
	goopt.Version = "Chmod"
	goopt.Summary = "Change file mode of each FILE to MODE\nWith reference, change file mode of each FILE to that of RFILE"
	goopt.Usage = func() string {
		return fmt.Sprintf("Usage:\t%s [OPTION]... [MODE] FILE...\n or:\t%s [OPTION]... --reference=RFILE FILE...\n", os.Args[0], os.Args[0]) +
			goopt.Summary + "\n\n" + goopt.Help()
	}
	goopt.Description = func() string {
		return goopt.Summary + "\n\nUnless --help or --version is passed."
	}
	silent := goopt.Flag([]string{"-f", "--silent", "--quiet"}, nil, "Suppress most error messages", "")
	/*changes := goopt.Flag([]string{"-c", "--changes"}, nil, "Like verbose but only report changes", "")
	verbose := goopt.Flag([]string{"-v", "--verbose"}, nil, "Output each file as it is processed", "")*/
	nodereference := goopt.Flag([]string{"-h", "--no-dereference"}, []string{"--derference"}, "Affect symbolic links directly instead of dereferencing them", "Dereference symbolic links before operating on them (This is default)")
	preserveroot := goopt.Flag([]string{"--preserve-root"}, []string{"--no-preserve-root"}, "Don't recurse on '/'", "Treat '/' normally (This is default)")
	goopt.OptArg([]string{"--reference"}, "RFILE", "Use RFILE's owner and group", fromReference)
	recurse := goopt.Flag([]string{"-R", "--recursive"}, nil, "Operate recursively on files and directories", "")
	goopt.NoArg([]string{"--version"}, "outputs version information and exits", coreutils.Version)
	goopt.Parse(nil)
	if len(goopt.Args) == 0 {
		coreutils.PrintUsage()
	}
	coreutils.Noderef = *nodereference
	coreutils.Preserveroot = *preserveroot
	if !usingreference {
		coreutils.ParseMode(goopt.Args[0])
	}
	var filestomod []string
	for i := range goopt.Args[1:] {
		filestomod = append(filestomod, goopt.Args[i+1])
		if *recurse && (!*preserveroot || goopt.Args[i+1] != "/") {
			if coreutils.Recurse(&filestomod) {
				defer os.Exit(1)
			}
		}
	}
	for i := range filestomod {
		err := os.Chmod(filestomod[i], coreutils.Mode)
		if err != nil && !*silent {
			fmt.Fprintf(os.Stderr, "Error changing mode for file '%s': %v\n", filestomod[i], err)
			defer os.Exit(1)
			continue
		}
	}
	return
}
Beispiel #24
0
func main() {
	hostEnv := os.Getenv("HOST")
	portEnv := os.Getenv("PORT")

	// default to environment variable values (changes the help string :( )
	if hostEnv == "" {
		hostEnv = "*"
	}

	p := 8080
	if portEnv != "" {
		p, _ = strconv.Atoi(portEnv)
	}

	goopt.Usage = usage

	// server mode options
	host := goopt.String([]string{"-h", "--host"}, hostEnv, "host ip address to bind to")
	port := goopt.Int([]string{"-p", "--port"}, p, "port to listen on")

	// cli mode
	vendor := goopt.String([]string{"-v", "--vendor"}, "", "vendor for cli generation")
	status := goopt.String([]string{"-s", "--status"}, "", "status for cli generation")
	color := goopt.String([]string{"-c", "--color", "--colour"}, "", "color for cli generation")
	goopt.Parse(nil)

	args := goopt.Args

	// if any of the cli args are given, or positional args remain, assume cli
	// mode.
	if len(args) > 0 || *vendor != "" || *status != "" || *color != "" {
		cliMode(*vendor, *status, *color, args)
		return
	}
	// normalize for http serving
	if *host == "*" {
		*host = ""
	}

	http.HandleFunc("/v1/", buckle)
	http.HandleFunc("/favicon.png", favicon)
	http.HandleFunc("/", index)

	log.Println("Listening on port", *port)
	http.ListenAndServe(*host+":"+strconv.Itoa(*port), nil)
}
Beispiel #25
0
func main() {
	goopt.Parse(func() []string { return []string{} })

	if len(goopt.Args) < 1 {
		fmt.Println("You need to provide a go file argument.")
		os.Exit(1)
	}
	if *outname == "FILENAME" {
		*outname = goopt.Args[0][0 : len(goopt.Args[0])-3]
	}
	fs := make([]string, len(goopt.Args)+1)
	for i, f := range goopt.Args {
		fs[i] = f
	}
	fs[len(goopt.Args)] = "testing.go"
	makeSource("testing.go")
	e := compile.Compile(*outname, fs)
	if e != nil {
		fmt.Println(e)
		os.Exit(1)
	}
	if e != nil {
		return
	}
	fi, err := os.Stat(*outname)
	if err != nil {
		return
	}
	enc0, err := os.Open(*outname+".encrypted", os.O_WRONLY+os.O_TRUNC+os.O_CREAT, 0644)
	if err != nil {
		return
	}
	enc, err := crypt.Encrypt(key, privatekey, enc0, fi.Size, sequence)
	if err != nil {
		return
	}
	plain, err := os.Open(*outname, os.O_RDONLY, 0644)
	if err != nil {
		return
	}
	_, err = io.Copyn(enc, plain, fi.Size)
	if err != nil {
		return
	}
}
Beispiel #26
0
func main() {
	goopt.Author = "William Pearson"
	goopt.Version = "Sync"
	goopt.Summary = "Flush filesystem buffers"
	goopt.Usage = func() string {
		return fmt.Sprintf("Usage:\t%s OPTION\n", os.Args[0]) + goopt.Summary + "\n\n" + goopt.Help()
	}
	goopt.Description = func() string {
		return goopt.Summary + "\n\nUnless an option is passed to it."
	}
	goopt.NoArg([]string{"-v", "--version"}, "outputs version information and exits", coreutils.Version)
	goopt.Parse(nil)
	if len(goopt.Args) != 0 {
		coreutils.PrintUsage()
	}
	Sync()
	return
}
Beispiel #27
0
func main() {
	goopt.Suite = "DevTodo2"
	goopt.Version = "2.1"
	goopt.Author = "Alec Thomas <*****@*****.**>"
	goopt.Description = func() string {
		return `DevTodo is a program aimed specifically at programmers (but usable by anybody
at the terminal) to aid in day-to-day development.

It maintains a list of items that have yet to be completed, one list for each
project directory. This allows the programmer to track outstanding bugs or
items that need to be completed with very little effort.

Items can be prioritised and are displayed in a hierarchy, so that one item may
depend on another.


todo2 [-A]
  Display (all) tasks.

todo2 [-p <priority>] -a <text>
  Create a new task.

todo2 -d <index>
  Mark a task as complete.

todo2 [-p <priority>] -e <task> [<text>]
  Edit an existing task.`
	}
	goopt.Summary = "DevTodo2 - a hierarchical command-line task manager"
	goopt.Usage = func() string {
		return fmt.Sprintf("usage: %s [<options>] ...\n\n%s\n\n%s",
			os.Args[0], goopt.Summary, goopt.Help())
	}
	goopt.Parse(nil)

	tasks, err := loadTaskList()
	if err != nil {
		fatal("%s", err)
	}
	if tasks == nil {
		tasks = NewTaskList()
	}
	processAction(tasks)
}
Beispiel #28
0
func main() {
	goopt.Author = "William Pearson"
	goopt.Version = "Echo"
	goopt.Summary = "Echo ARGs to stdout."
	goopt.Usage = func() string {
		return fmt.Sprintf("Usage:\t%s [SHORT-OPTION] ARGS...\n or:\t%s LONG-OPTION\n", os.Args[0], os.Args[0]) + goopt.Summary + "\n\n" + goopt.Help()
	}
	goopt.Description = func() string {
		return goopt.Summary + "\n\nValid backslash escape sequences go here."
	}
	goopt.NoArg([]string{"-v", "--version"}, "outputs version information and exits", coreutils.Version)
	newline := goopt.Flag([]string{"-n"}, nil, "Don't print out a newline after ARGS", "")
	backslashescape := goopt.Flag([]string{"-e"}, []string{"-E"}, "Enable interpretation of backslash escapes", "Disable interpretation of backslash escapes")

	goopt.Parse(nil)
	argstring := strings.Join(goopt.Args, " ")
	if *backslashescape {
		argstring = fmt.Sprintf("%q", argstring)
		argstring = strings.Replace(argstring, "\\\\", "\\", -1)
		validEscapeSeqs := "\\abcefnrtv0x"
		for i := 0; i < len(argstring); i++ {
			if argstring[i] != '\\' {
				continue
			}
			if !strings.Contains(validEscapeSeqs, string(argstring[i+1])) {
				argstring = argstring[:i] + "\\" + argstring[i:]
			}
			i++
		}
		backslashstring, err := strconv.Unquote(argstring)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Error encountered when interpreting escape sequences: %v\n", err)
			os.Exit(1)
		}
		argstring = backslashstring
	}
	nl := "\n"
	if *newline {
		nl = ""
	}
	fmt.Printf("%s%s", argstring, nl)
	return
}
Beispiel #29
0
func main() {
	goopt.Author = "William Pearson"
	goopt.Version = "Whoami"
	goopt.Summary = "Prints username of current user"
	goopt.Usage = func() string {
		return fmt.Sprintf("Usage: %s OPTION\n", os.Args[0]) + goopt.Summary + "\n\n" + goopt.Help()
	}
	goopt.Description = func() string {
		return goopt.Summary + "\n\nUnless an option is passed to it."
	}
	goopt.NoArg([]string{"-v", "--version"}, "outputs version information and exits", coreutils.Version)
	goopt.Parse(nil)
	currentUser, err := user.Current()
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error getting current user: %v\n", err)
		return
	}
	fmt.Println(currentUser.Username)
	return
}
Beispiel #30
0
func main() {
	goopt.Author = "Aaron Muir Hamilton"
	goopt.Version = "Sleep"
	goopt.Summary = "Pause for NUMBER seconds. SUFFIX may be 's' for seconds (the default), 'm' for minutes, 'h' for hours, or 'd' for days. NUMBER may be either an integer or a floating point number."
	goopt.Usage = func() string {
		return fmt.Sprintf("Usage of %s:\n\t   %s NUMBER[SUFFIX]\n\tor %s OPTION\n", os.Args[0], os.Args[0], os.Args[0]) +
			goopt.Summary + "\n\n" + goopt.Help()
	}
	goopt.Description = func() string { return goopt.Summary + "\n\nUnless an option is passed to it." }
	goopt.NoArg([]string{"-v", "--version"}, "outputs version information and exits", coreutils.Version)
	goopt.Parse(nil)
	if len(os.Args) == 1 {
		frown("missing operand")
	}
	var d time.Duration
	for i := range os.Args[1:] {
		d += parseDuration(os.Args[i+1])
	}
	time.Sleep(d)
	os.Exit(0)
}