Example #1
0
func main() {

	flag.Parse()

	if flag.NArg() < 1 {
		fmt.Println("Must specify path to a gouchstore compatible file")
		return
	} else if flag.NArg() < 2 {
		fmt.Println("Must specify path to the new compacted gouchstore file")
		return
	}

	var ops gouchstore.GouchOps
	if *memCompact {
		ops = gouchstore.NewMemCompactGouchOps()
	} else {
		ops = gouchstore.NewBaseGouchOps()
	}
	db, err := gouchstore.OpenEx(flag.Args()[0], gouchstore.OPEN_RDONLY, ops)
	if err != nil {
		fmt.Println(err)
		return
	}
	defer db.Close()

	err = db.Compact(flag.Arg(1))
	if err != nil {
		fmt.Println(err)
	}
}
Example #2
0
func main() {
	FILE = os.Stdin
	flag.Parse()
	versionTxt()
	sigChan := make(chan int, 0)

	d0 := make(chan chanT, 0)
	d1 := make(chan chanT, 0)
	c := make(chan string, 30)
	f := make(chan io.Reader, 5)

	setupSignal(sigChan)

	go pr(c, d0)

	// As soon as you introduce more than one file, your output
	// will get mixed up. How do you fix that?
	for i := 0; i < flag.NArg(); i++ {
		FILE, _ = Open(flag.Arg(i))
		f <- FILE
		go read(f, c, d1)

	}

	if flag.NArg() == 0 {
		f <- FILE
		go read(f, c, d1)
	}

	wait(d0, d1, sigChan, flag.NArg())

}
Example #3
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	var opt optionSet
	flag.BoolVar(&opt.v, "V", false, "show version.")
	flag.BoolVar(&opt.g, "g", false, "enable grep.")
	flag.BoolVar(&opt.search_binary, "search-binary", false, "search binary files for matches on grep enable.")
	flag.BoolVar(&opt.grep_only, "grep-only", false, "enable grep and disable file search.")
	flag.StringVar(&opt.ignore, "ignore", "", "pattern is ignored.")
	flag.BoolVar(&opt.hidden, "hidden", false, "search hidden files.")
	flag.BoolVar(&opt.ignorecase, "ignorecase", false, "ignore case distinctions in pattern.")
	flag.Parse()

	if opt.v {
		fmt.Printf("version: %s\n", version)
		os.Exit(0)
	}

	if flag.NArg() < 1 {
		usage()
	}
	pattern := flag.Arg(0)
	fpath := "."
	if flag.NArg() >= 2 {
		fpath = strings.TrimRight(flag.Arg(1), separator)
	}

	g := newGorep(pattern, &opt)
	chans := g.kick(fpath)

	g.report(chans, verifyColor())
}
Example #4
0
func main() {
	var pubFile, privFile string
	var help, listen, stayOpen bool
	flag.BoolVar(&help, "h", false, "display a short usage message")
	flag.BoolVar(&stayOpen, "k", false, "keep listening after client disconnects")
	flag.BoolVar(&listen, "l", false, "listen for incoming connections")
	flag.StringVar(&privFile, "s", "", "path to signature key")
	flag.StringVar(&pubFile, "v", "", "path to verification key")
	flag.Parse()

	if help {
		usage()
		os.Exit(1)
	}

	loadID(privFile, pubFile)
	defer func() {
		if idPriv != nil {
			zero(idPriv[:], 0)
		}
	}()

	if listen {
		if flag.NArg() != 1 {
			fmt.Println("A port is required (and should be the only argument) when listening.")
		}
		listener(stayOpen, flag.Arg(0))
		return
	}

	if flag.NArg() != 2 {
		fmt.Println("An address and port are required (and should be the only arguments).")
	}
	sender(flag.Arg(0) + ":" + flag.Arg(1))
}
Example #5
0
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))
			}
		}
	}
}
Example #6
0
func main() {
	flag.Parse()

	if email == "" || password == "" {
		fmt.Println("Invalid E-Mail or Password\n")
		flag.Usage()
		os.Exit(-1)
	}

	if flag.NArg()%2 == 0 {
		flag.Usage()
		os.Exit(-1)
	}
	imsi := flag.Arg(0)
	tags := make([]map[string]string, (flag.NArg()-1)/2)
	idx := 0
	for i := 1; i < flag.NArg(); i += 2 {
		k := flag.Arg(i)
		v := flag.Arg(i + 1)
		tag := map[string]string{"tagName": k, "tagValue": v}
		tags[idx] = tag
		idx++
	}
	fmt.Println(tags)

	c, err := goracom.NewClient(email, password)
	errToExit(err)
	s := c.NewSubscriber()
	sub, err := s.Tags(imsi, tags)
	errToExit(err)
	printSubscriber(*sub)
}
Example #7
0
func main() {
	start := time.Now()

	flag.Parse()

	if *version {
		fmt.Printf("inspectFile %d.%d.%d\n", Version[0], Version[1], Version[2])
		return
	}
	if *flserve != "" {
		fmt.Printf("Startinf server at %s. Use CTRL+C to quit.\n", *flserve)
		listen(*flserve)
		return
	}
	if *fltools != "" {
		initTools(*fltools)
	}
	if *dir {
		if flag.NArg() != 1 {
			fmt.Println("You must pass a directory name!!!")
			return
		}
		inspectdir(flag.Arg(0))
	} else if flag.NArg() != 1 {
		fmt.Println("You must pass a file name in parameter!!!")
		return
	} else {
		output = inspectfile(flag.Arg(0), nil)
	}
	//output = inspectsfile("/media/sf_Temp/Benchmark.pptx", output)
	fmt.Printf("Output: %s \n", output)
	fmt.Printf("ToolsVersion: %s\n", ExportToolsVersion())

	fmt.Printf("Took %v to run.\n", time.Since(start))
}
Example #8
0
func main() {

	if flag.NArg() == 0 {
		fmt.Printf("[Error] path or file must provide one.\n\n")
		flag.Usage()
		os.Exit(retFail)
	}

	for i := 0; i < flag.NArg(); i++ {
		path := strings.TrimSpace(flag.Arg(i))
		switch dir, err := os.Stat(path); {
		case err != nil:
			//fmt.Printf("[Error] error in Stat(): %s.\n", err)
			panic(err)
		case dir.IsDir():
			if path, err = filepath.Abs(path); err != nil {
				panic(err)
			}
			dealDirWithWhiteList(path, cmd, suffixArray)
		default:
			if path, err = filepath.Abs(path); err != nil {
				panic(err)
			}
			dealFileWithWhiteList(path, cmd, suffixArray)
		}
	}
}
Example #9
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)

	}

}
Example #10
0
func convertCmd() {
	if flag.NArg() != 2 && flag.NArg() != 3 {
		log.Fatal("Error: wrong number of arguments (expected input and output files)")
	}

	// should refactor this to open both files first, then do processing? not
	// sure what best practice is.

	inFname := flag.Arg(1)
	outFname := flag.Arg(2)

	bm, b := loadIn(inFname)

	if b == nil {
		log.Fatal("null bom")
	}
	if *inFormat == "csv" && bm == nil {
		// TODO: from inname? if ShortName?
		bm = &BomMeta{Name: "untitled",
			Owner: anonUser.name}
		b.Version = "unversioned"
	}

	b.Created = time.Now()
	b.Progeny = "File import from " + inFname + " (" + *inFormat + ")"

	if err := bm.Validate(); err != nil {
		log.Fatal("loaded bommeta not valid: " + err.Error())
	}
	if err := b.Validate(); err != nil {
		log.Fatal("loaded bom not valid: " + err.Error())
	}

	dumpOut(outFname, bm, b)
}
Example #11
0
func listCmd() {

	openBomStore()
	var bomMetas []BomMeta
	var err error
	if flag.NArg() > 2 {
		log.Fatal("Error: too many arguments...")
	}
	if flag.NArg() == 2 {
		name := flag.Arg(1)
		if !isShortName(name) {
			log.Fatal("Error: not a possible username: "******"")
		if err != nil {
			log.Fatal(err)
		}
	}
	for _, bm := range bomMetas {
		fmt.Println(bm.Owner + "/" + bm.Name)
	}
}
Example #12
0
func dumpCmd() {
	if flag.NArg() != 3 && flag.NArg() != 4 {
		log.Fatal("Error: wrong number of arguments (expected user and BOM name, optional file)")
	}

	userStr := flag.Arg(1)
	nameStr := flag.Arg(2)

	if !isShortName(userStr) || !isShortName(nameStr) {
		log.Fatal("Error: not valid ShortName: " + userStr +
			" and/or " + nameStr)
	}

	var fname string
	if flag.NArg() == 4 {
		fname = flag.Arg(3)
	} else {
		fname = ""
	}

	openBomStore()
	openAuthStore()

	bm, b, err := bomstore.GetHead(ShortName(userStr), ShortName(nameStr))
	if err != nil {
		log.Fatal(err)
	}

	dumpOut(fname, bm, b)
}
Example #13
0
func main() {
	var dockerAddr string
	var transferAddr string
	var debug bool
	flag.BoolVar(&debug, "DEBUG", false, "enable debug")
	flag.StringVar(&dockerAddr, "d", "tcp://192.168.99.100:2376", "docker daemon addr")
	flag.StringVar(&transferAddr, "t", "10.200.8.37:8433", "transfer addr")
	flag.Parse()
	if flag.NArg() < 1 {
		fmt.Println("need at least one container id")
		return
	}
	if debug {
		log.SetLevel(log.DebugLevel)
	}

	cli, _ := client.NewEnvClient()

	metric.SetGlobalSetting(cli, 2, 3, "vnbe", "eth0")
	client := statsd.CreateStatsDClient(transferAddr)
	ctx := context.Background()

	for i := 0; i < flag.NArg(); i++ {
		if c, err := cli.ContainerInspect(ctx, flag.Arg(i)); err != nil {
			fmt.Println(flag.Arg(i), err)
			continue
		} else {
			go start_watcher(client, c.ID, c.State.Pid)
		}
	}
	for {
	}
}
Example #14
0
func main() {
	outFilename := flag.String("o", "", `output file`)
	yyExtraName = flag.String("yyextra", "", "Data type stored in yyextra (use an empty string for no yyextra)")
	standalone = flag.Bool("s", false, `standalone code; NN_FUN macro substitution, no Lex() method`)
	customError = flag.Bool("e", false, `custom error func; no Error() method`)
	autorun = flag.Bool("r", false, `run generated program`)
	nfadotFile := flag.String("nfadot", "", `show NFA graph in DOT format`)
	dfadotFile := flag.String("dfadot", "", `show DFA graph in DOT format`)
	flag.Parse()

	nfadot = createDotFile(*nfadotFile)
	dfadot = createDotFile(*dfadotFile)
	defer func() {
		if nfadot != nil {
			dieErr(nfadot.Close(), "Close")
		}
		if dfadot != nil {
			dieErr(dfadot.Close(), "Close")
		}
	}()
	infile, outfile := os.Stdin, os.Stdout
	var err error
	if flag.NArg() > 0 {
		dieIf(flag.NArg() > 1, "nex: extraneous arguments after", flag.Arg(0))
		dieIf(strings.HasSuffix(flag.Arg(0), ".go"), "nex: input filename ends with .go:", flag.Arg(0))
		basename := flag.Arg(0)
		n := strings.LastIndex(basename, ".")
		if n >= 0 {
			basename = basename[:n]
		}
		infile, err = os.Open(flag.Arg(0))
		dieErr(err, "nex")
		defer infile.Close()
		if !*autorun {
			if *outFilename == "" {
				outfile, err = os.Create(basename + ".nn.go")
			} else {
				outfile, err = os.Create(*outFilename)
			}
			dieErr(err, "nex")
			defer outfile.Close()
		}
	}
	if *autorun {
		tmpdir, err := ioutil.TempDir("", "nex")
		dieIf(err != nil, "tempdir:", err)
		defer func() {
			dieErr(os.RemoveAll(tmpdir), "RemoveAll")
		}()
		outfile, err = os.Create(tmpdir + "/lets.go")
		dieErr(err, "nex")
		defer outfile.Close()
	}
	process(outfile, infile)
	if *autorun {
		c := exec.Command("go", "run", outfile.Name())
		c.Stdin, c.Stdout, c.Stderr = os.Stdin, os.Stdout, os.Stderr
		dieErr(c.Run(), "go run")
	}
}
Example #15
0
func main() {
	flag.Usage = printUsage
	flag.Parse()
	if flag.NArg() != 1 {
		printUsage()
		os.Exit(2)
	}
	clientName := fmt.Sprintf("%s:%d", *subHostname, *subPortNum)
	client, err := rpc.DialHTTP("tcp", clientName)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error dialing\t%s\n", err)
		os.Exit(1)
	}
	for _, subcommand := range subcommands {
		if flag.Arg(0) == subcommand.command {
			if flag.NArg()-1 != subcommand.numArgs {
				printUsage()
				os.Exit(2)
			}
			subcommand.cmdFunc(client, flag.Args()[1:])
			os.Exit(3)
		}
	}
	printUsage()
	os.Exit(2)
}
Example #16
0
func main() {
	flag.Usage = usage
	flag.Parse()
	if *tabwidth < 0 {
		fmt.Fprintf(os.Stderr, "negative tabwidth %d\n", *tabwidth)
		os.Exit(2)
	}

	if flag.NArg() == 0 {
		if err := processFile("/dev/stdin"); err != nil {
			report(err)
		}
	}

	for i := 0; i < flag.NArg(); i++ {
		path := flag.Arg(i)
		switch dir, err := os.Stat(path); {
		case err != nil:
			report(err)
		case dir.IsRegular():
			if err := processFile(path); err != nil {
				report(err)
			}
		case dir.IsDirectory():
			walkDir(path)
		}
	}

	os.Exit(exitCode)
}
Example #17
0
func main() {
	flag.Usage = usage
	flag.Parse()

	command := ""
	if flag.NArg() > 0 {
		command = flag.Arg(0)
		switch command {
		case "convert":
			if flag.NArg() <= 1 {
				fmt.Fprintln(os.Stderr, "missing cover profile")
				os.Exit(1)
			}
			if err := convertProfiles(flag.Args()[1:]...); err != nil {
				fmt.Fprintln(os.Stderr, "error:", err)
				os.Exit(1)
			}
		case "annotate":
			os.Exit(annotateSource())
		case "report":
			os.Exit(reportCoverage())
		case "test":
			if err := runTests(flag.Args()[1:]); err != nil {
				fmt.Fprintln(os.Stderr, "error:", err)
				os.Exit(1)
			}
		default:
			fmt.Fprintf(os.Stderr, "Unknown command: %#q\n\n", command)
			usage()
		}
	} else {
		usage()
	}
}
Example #18
0
func main() {
	var Loadpagelist = flag.Bool("l", false, "\tLoad the ed2klink page url list")
	flag.Parse()
	if *Loadpagelist {
		listfilename := flag.Arg(0)
		m, err := loadvv(listfilename)
		if err == nil {
			loadlist(m)
		} else {
			fmt.Printf("File %s not exist.\n", listfilename)
		}
	} else {
		if flag.NArg() > 0 {
			m := make(map[int]string)
			for p, i := 0, 0; i < flag.NArg(); i++ {
				if strings.HasPrefix(flag.Arg(i), "http://") {
					m[p] = flag.Arg(i)
					p++
				}
			}
			loadlist(m)
		} else {
			help()
		}
	}
}
Example #19
0
File: main.go Project: mhoc/msp
func main() {
	log.Trace("-m-", "Opening input file")

	// Parse debug flags
	flag.BoolVar(&log.LOG_TOKENS, "log-tokens", false, "Enable list of parsed tokens")
	flag.BoolVar(&log.LOG_TRACE, "log-trace", false, "Enable trace logging of debug output")
	flag.BoolVar(&log.EXTENSIONS, "extensions", false, "Enables parser extensions for additional features. See README for a list of these.")
	flag.Parse()

	// Init builtin functions
	ast.InitBuiltins()

	// Parse command line arguments
	var file *os.File
	var err error
	if flag.NArg() == 0 {
		log.Trace("-m-", "Reading from stdin")
		file = os.Stdin
	} else if flag.NArg() == 1 {
		log.Trace("-m-", "Reading from file "+flag.Arg(0))
		file, err = os.Open(flag.Arg(0))
	} else {
		panic("Must provide filename to read from or no filename at all")
	}

	if err != nil {
		panic("File name provided does not exist")
	}

	log.Trace("-m-", "Beginning lex")
	yyParse(NewLexer(file))

}
Example #20
0
func getCmdLine() (result cmdlineT) {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
		fmt.Fprintln(os.Stderr,
			"\t[options] datadir [cert.pem key.pem]")
		flag.PrintDefaults()
	}

	flag.StringVar(&result.laddr, "listen", ":8000",
		"listen address, \":8080\" or \"localhost:5050\"")
	flag.BoolVar(&result.tls, "tls", false, "use TLS. "+
		"Requires cert.pem and key.pem positional args "+
		"(see crypto/tls/generate_cert.go).")
	flag.StringVar(&result.singleuser, "singleuser", "",
		"Always logged in as specified user, without password")
	flag.IntVar(&result.quittimeout, "quittimeout", 1,
		"seconds to wait when shutting down")
	flag.Parse()

	if !result.tls {
		if flag.NArg() != 1 {
			log.Fatalln("Expecting 1 positional arg, found",
				flag.NArg())
		}
	} else {
		if flag.NArg() != 3 {
			log.Fatalln("TLS requires 3 positional args, found",
				flag.NArg())
		}
		result.cert = flag.Arg(1)
		result.key = flag.Arg(2)
	}
	result.dir = flag.Arg(0)
	return
}
Example #21
0
func gofmtMain() {
	flag.Usage = usage
	flag.Parse()

	if flag.NArg() == 0 {
		if err := processFile("", "<standard input>", os.Stdin, os.Stdout, true); err != nil {
			report(err)
		}
		return
	}

	for i := 0; i < flag.NArg(); i++ {
		path := flag.Arg(i)
		switch dir, err := os.Stat(path); {
		case err != nil:
			report(err)
		case dir.IsDir():
			walkDir(path)
		default:
			if err := processFile(filepath.Dir(path), path, nil, os.Stdout, false); err != nil {
				report(err)
			}
		}
	}
}
Example #22
0
func main() {
	flag.Usage = Usage
	flag.IntVar(&count, "count", countDefault, countHelp)
	flag.IntVar(&count, "c", countDefault, countHelp+" (shorthand)")
	flag.StringVar(&langNum, "lang", "", langHelp)
	flag.StringVar(&langNum, "l", "", langHelp+"(shorthand)")
	flag.Parse()

	if flag.NArg() == 0 || flag.NArg() > 1 {
		flag.Usage()
	}

	query := flag.Arg(0)
	url, err := searchString(Query{query, langNum, count})
	if err != nil {
		log.Fatal(err)
	}

	client := &http.Client{}
	res, err := requestSearch(url, client)
	if err != nil {
		log.Fatal(err)
	}

	buffer, err := ioutil.ReadAll(res.Body)
	if err != nil {
		log.Fatal(err)
	}

	err = printFromJSON(count, buffer)
	if err != nil {
		log.Fatal(err)
	}
}
Example #23
0
func main() {
	flag.Parse()

	imagick.Initialize()
	defer imagick.Terminate()
	mw := imagick.NewMagickWand()
	defer mw.Destroy()
	var err error

	if flag.NArg() < 1 {
		fmt.Println("Usage: imagick_profiles <imgfile> [<proftype>]\n")
		os.Exit(1)
	}
	basename := flag.Arg(0)
	err = mw.ReadImage(basename)
	if err != nil {
		fmt.Println("ReadImage Error:", err)
		os.Exit(1)
	}
	if flag.NArg() == 1 {
		profs := mw.GetImageProfiles("*")
		fmt.Println(profs)
	} else {
		proftype := flag.Arg(1)
		prof := mw.GetImageProfile(proftype)
		fmt.Print(prof)
	}
}
Example #24
0
func main() {
	flag.Parse()

	if flag.NArg() < 2 {
		flag.Usage()
	}

	u := flag.Arg(0)

	cmdName := flag.Arg(1)
	cmd, ok := commands[cmdName]
	if !ok {
		fmt.Fprintf(os.Stderr, "Unknown command: %v\n", cmdName)
		flag.Usage()
	}
	if cmd.nargs == 0 {
	} else if cmd.nargs < 0 {
		reqargs := -cmd.nargs
		if flag.NArg()-2 < reqargs {
			fmt.Fprintf(os.Stderr, "Incorrect arguments for %v\n", cmdName)
			flag.Usage()
		}
	} else {
		if flag.NArg()-2 != cmd.nargs {
			fmt.Fprintf(os.Stderr, "Incorrect arguments for %v\n", cmdName)
			flag.Usage()
		}
	}

	cmd.f(u, flag.Args()[2:])
}
Example #25
0
func main() {
	flag.Parse()
	if flag.NArg() != 1 && flag.NArg() != 2 {
		flag.Usage()
		fmt.Fprintf(os.Stderr, "Usage: %s <remote> [<local>]\n", os.Args[0])
		os.Exit(2)
	}

	handler := ext.FatalHandler(log15.CallerFileHandler(log15.StderrHandler))
	if flagVeryVerbose {
		handler = log15.LvlFilterHandler(log15.LvlDebug, handler)
	} else if flagVerbose {
		handler = log15.LvlFilterHandler(log15.LvlInfo, handler)
	}
	log15.Root().SetHandler(handler)

	local := "."
	if flag.NArg() == 2 {
		local = flag.Arg(1)
	}

	m := sftpsync.SyncManager{
		Local:     local,
		Remote:    flag.Arg(0),
		SkipFiles: skipFiles,
		SkipDirs:  skipDirs,
		Append:    flagAppend,
		DryRun:    flagDryRun,
	}
	err := m.Run()
	if err != nil {
		log.Crit("run error", "err", err)
		return
	}
}
Example #26
0
func main() {
	flag.Parse()
	if *show_key {
		if flag.NArg() < 1 {
			flag.Usage()
			os.Exit(1)
		}
		for _, seed := range flag.Args() {
			key, err := issh.GetAuthorizedKey(seed)
			if err != nil {
				panic("Failed to create a key: " + err.Error())
			}
			fmt.Printf("public key for \"%s\"\n"+
				"command=\"exit 1\",no-port-forwarding,no-X11-forwarding,no-pty %s "+
				"issh generated from seed: '%s'\n",
				seed, bytes.TrimRight(key, "\r\n \t"), seed)
		}
		return
	}

	if flag.NArg() != 2 {
		flag.Usage()
		os.Exit(1)
	}

	user, host, port := parseUserHostPort(flag.Arg(1))
	stdout, exitcode, err := issh.Run(user, host, port, flag.Arg(0))
	if err != nil {
		panic("Failed to execute remote command: " + err.Error())
	}

	os.Stdout.Write(stdout)
	os.Exit(exitcode)
}
Example #27
0
func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage: %s [ <project directory> ]\n",
			os.Args[0])
		flag.PrintDefaults()
	}

	var cf config

	flag.StringVar(&cf.projectName, "n", "",
		"base package name for the project, e.g. github.com/user/proj")
	flag.BoolVar(&cf.update, "u", false,
		"update dependency submodules from their remote repos")
	flag.BoolVar(&cf.prune, "p", false,
		"prune unused dependency submodules")

	flag.Parse()

	cf.rootDir = "."
	switch {
	case flag.NArg() == 1:
		cf.rootDir = flag.Arg(1)
	case flag.NArg() > 1:
		flag.Usage()
		os.Exit(2)
	}

	if err := run(&cf); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}
Example #28
0
func (self *Application) ExecClient() (result bool) {
	if flag.NArg() == 0 {
		ShowApplicationUsage()
		return false
	}

	rpcClient, err := rpc.Dial(GetServiceSocket(self.tcpPort))
	if err != nil {
		fmt.Fprintf(os.Stderr, "Cannot open RPC connection: %v\n", err)
		return false
	}

	switch flag.Arg(0) {
	case "close":
		ClientCloseService(rpcClient)
	case "reload":
		ClientReloadService(rpcClient)
	case "scan":
		if flag.NArg() != 2 {
			ShowApplicationUsage()
			return false
		}
		inputPath, err := filepath.Abs(flag.Arg(1))
		if err != nil {
			fmt.Fprintf(os.Stderr, "Cannot get full path from '%s'\n", flag.Arg(1))
			return false
		}
		result := ClientScanEmotions(rpcClient, inputPath)
		fmt.Fprintf(os.Stdout, "Text has %d words, %.2f%% positive and %.2f%% negative\n", result.WordCount, result.PercentPositive, result.PercentNegative)
	default:
		ShowApplicationUsage()
		return false
	}
	return true
}
Example #29
0
func gofmtMain() {
	flag.Usage = usage
	flag.Parse()

	if options.TabWidth < 0 {
		fmt.Fprintf(os.Stderr, "negative tabwidth %d\n", options.TabWidth)
		exitCode = 2
		return
	}

	if flag.NArg() == 0 {
		if err := processFile("<standard input>", os.Stdin, os.Stdout, true); err != nil {
			report(err)
		}
		return
	}

	for i := 0; i < flag.NArg(); i++ {
		path := flag.Arg(i)
		switch dir, err := os.Stat(path); {
		case err != nil:
			report(err)
		case dir.IsDir():
			walkDir(path)
		default:
			if err := processFile(path, nil, os.Stdout, false); err != nil {
				report(err)
			}
		}
	}
}
Example #30
0
func main() {
	var location = flag.String("l", "", "Location alias of data centre to host load balancer")
	var desc = flag.String("desc", "", "Textual description of the load balancer")
	var status = flag.String("status", "enabled", "Whether to an 'enabled' or 'disabled' load balancer")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s [options]  <Load Balancer Name>\n", path.Base(os.Args[0]))
		flag.PrintDefaults()
	}

	flag.Parse()
	fmt.Println(flag.NArg())
	if flag.NArg() != 1 {
		flag.Usage()
		os.Exit(1)
	}

	client, err := clcv2.NewCLIClient()
	if err != nil {
		exit.Fatal(err.Error())
	}

	lb, err := client.CreateSharedLoadBalancer(flag.Arg(0), *desc, *status, *location)
	if err != nil {
		exit.Fatalf("failed to create shared load balancer %q: %s", flag.Arg(0), err)
	}

	fmt.Printf("Created %s load balancer %s, %q with IP %s\n", *location, lb.ID, lb.Name, lb.IpAddress)
}