Golang Usage示例

说明

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

编程语言: Golang

命名空间/包名称: flag

示例#1
文件: goobar.go 项目: sofuture/goobar

func main() {
	flag.Usage = Usage
	flag.Parse()

	if *showVersion {
		fmt.Println("goobar", Version)
		os.Exit(0)
	}

	if *listenAddress == "" {
		fmt.Fprintln(os.Stderr, "you must supply an address to listen on")
		flag.Usage()
		os.Exit(1)
	}

	if *memcacheBackend == "" {
		fmt.Fprintln(os.Stderr, "you must specify a memcached backend")
		flag.Usage()
		os.Exit(1)
	}

	log.SetPrefix("goobar ")
	log.SetFlags(log.Ldate | log.Lmicroseconds)

	tsock, err := net.Listen("tcp", *listenAddress)
	if err != nil {
		panic(err)
	}

	server.Main(tsock)
}

示例#2
文件: facebook.go 项目: arv/noms-old

func main() {
	flag.Usage = usage
	flag.Parse()
	cachingHTTPClient = util.CachingHttpClient()

	if *tokenFlag == "" || cachingHTTPClient == nil {
		flag.Usage()
		return
	}

	ds = clientFlags.CreateDataset()
	if ds == nil {
		flag.Usage()
		return
	}
	defer ds.Store().Close()

	if err := clientFlags.CreateProgressFile(); err != nil {
		fmt.Println(err)
	} else {
		defer clientFlags.CloseProgressFile()
	}

	token := oauth2.Token{AccessToken: *tokenFlag}
	authHTTPClient = oauth2.NewClient(oauth2.NoContext, oauth2.StaticTokenSource(&token))

	start = time.Now()
	var user = getUser()
	printStats(user)

	userRef := ds.Store().WriteValue(user)
	fmt.Printf("userRef: %s\n", userRef.TargetRef())
	_, err := ds.Commit(userRef)
	d.Exp.NoError(err)
}

示例#3
文件: main.go 项目: jmcvetta/magicsquare

func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage: %s size\n", os.Args[0])
		fmt.Fprintf(os.Stderr, "    Must specify an odd integer for size\n")
		flag.PrintDefaults()
	}
	flag.Parse()
	if flag.NArg() != 1 {
		flag.Usage()
		return
	}
	size, err := strconv.Atoi(flag.Arg(0))
	if err != nil {
		flag.Usage()
		return
	}
	square, err := magicsquare.MagicSquare(size)
	if err != nil {
		flag.Usage()
		return
	}
	for _, row := range square {
		for _, col := range row {
			fmt.Printf("%5v", col)
		}
		fmt.Printf("\n")
	}

}

示例#4
文件: mattermost.go 项目: cbayleOL/platform

func cmdCreateTeam() {
	if flagCmdCreateTeam {
		if len(flagTeamName) == 0 {
			fmt.Fprintln(os.Stderr, "flag needs an argument: -team_name")
			flag.Usage()
			os.Exit(1)
		}

		if len(flagEmail) == 0 {
			fmt.Fprintln(os.Stderr, "flag needs an argument: -email")
			flag.Usage()
			os.Exit(1)
		}

		c := &api.Context{}
		c.RequestId = model.NewId()
		c.IpAddress = "cmd_line"

		team := &model.Team{}
		team.DisplayName = flagTeamName
		team.Name = flagTeamName
		team.Email = flagEmail
		team.Type = model.TEAM_INVITE

		api.CreateTeam(c, team)
		if c.Err != nil {
			if c.Err.Message != "A team with that domain already exists" {
				l4g.Error("%v", c.Err)
				flushLogAndExit(1)
			}
		}

		os.Exit(0)
	}
}

示例#5
文件: webserver-loadtest.go 项目: kgoess/webserver-loadtest

// Remember Exit(0) is success, Exit(1) is failure
func main() {
	flag.Var(&slaveList, "control", "list of ip:port addresses to control")
	flag.Parse()
	if len(*testUrl) == 0 {
		flag.Usage()
		os.Exit(1)
	}
	if len(slaveList) > 0 && *listen != 0 {
		fmt.Fprintf(os.Stderr, "You can't have both --listen and --control flags")
		flag.Usage()
		os.Exit(1)
	}
	rand.Seed(time.Now().Unix())

	// set up logging
	logWriter, err := os.OpenFile(*logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
	if err != nil {
		println(err)
		os.Exit(1)
	}
	log.SetOutput(logWriter)

	TRACE = log.New(ioutil.Discard,
		"TRACE: ",
		log.Ldate|log.Ltime|log.Lshortfile)
	INFO = log.New(logWriter,
		"INFO: ",
		log.Ldate|log.Ltime|log.Lshortfile)
	ERROR = log.New(logWriter,
		"ERROR: ",
		log.Ldate|log.Ltime|log.Lshortfile)
	INFO.Println("beginning run")

	os.Exit(realMain())
}

示例#6
文件: issues.go 项目: seikichi/gopl

func main() {
	token := os.Getenv("GITHUB_ACCESS_TOKEN")
	client := github.NewClient(token)

	flag.Usage = func() { fmt.Print(usage) }
	flag.Parse()

	args := flag.Args()
	if len(args) == 0 {
		flag.Usage()
		os.Exit(1)
	}
	switch args[0] {
	case "create":
		create(client, args[1:])
	case "show":
		show(client, args[1:])
	case "search":
		search(client, args[1:])
	case "edit":
		edit(client, args[1:])
	case "close":
		close(client, args[1:])
	case "reopen":
		reopen(client, args[1:])
	default:
		flag.Usage()
		os.Exit(1)
	}
}

示例#7
文件: jedie.go 项目: NovemberFoxtrot/jedie

func commands(args []string) {
	var cfg config
	var err error

	fmt.Println(args)

	if len(args) == 0 {
		flag.Usage()
		return
	}

	switch args[0] {
	case "new":
		path := args[1]
		if path == "" {
			flag.Usage()
			os.Exit(1)
		}
		err = cfg.New(path)
		checkFatal(err)
	case "build":
		err = cfg.load("_config.yml")
		checkFatal(err)
		err = cfg.Build()
		checkFatal(err)
	case "serve":
		err = cfg.load("_config.yml")
		checkFatal(err)
		err = cfg.Serve()
		checkFatal(err)
	default:
		flag.Usage()
	}
}

示例#8
文件: trans-diff.go 项目: henmt/2015

func init() {
	flag.StringVar(&in, "in", "", "BAM file to be processed.")
	flag.StringVar(&annot, "annot", "", "file name of a GFF file containing annotations.")
	flag.Float64Var(&thresh, "thresh", 1, "log score threshold for inclusion of feature.")
	flag.Var(&classes, "class", "comma separated set of annotation classes to analyse.")
	flag.BoolVar(&pretty, "pretty", true, "outfile JSON data indented.")
	flag.IntVar(&minLength, "min", 20, "minimum length read considered.")
	flag.IntVar(&maxLength, "max", 35, "maximum length read considered.")
	flag.IntVar(&minId, "minid", 90, "minimum percentage identity for mapped bases.")
	flag.IntVar(&minQ, "minQ", 20, "minimum per-base sequence quality.")
	flag.Float64Var(&minAvQ, "minAvQ", 30, "minimum average per-base sequence quality.")
	flag.IntVar(&mapQ, "mapQ", 0, "minimum mapping quality [0, 255).")
	flag.IntVar(&binLength, "bin", 1e7, "bin length.")
	help := flag.Bool("help", false, "output this usage message.")
	flag.Parse()
	mapQb = byte(mapQ)
	if *help {
		flag.Usage()
		os.Exit(0)
	}
	if in == "" || !annotOK(annot, classes) || mapQ < 0 || mapQ > 254 {
		flag.Usage()
		os.Exit(1)
	}
}

示例#9
文件: main.go 项目: uwedeportivo/codejam

func main() {
	help := flag.Bool("help", false, "show this message")
	inFile := flag.String("in", "", "input filename (required)")
	outFile := flag.String("out", "", "output filename (stdout if omitted)")

	flag.Parse()

	if *help {
		flag.Usage()
		os.Exit(0)
	}

	if len(*inFile) == 0 {
		flag.Usage()
		os.Exit(0)
	}

	pr := codejam.NewProblem(*inFile, *outFile)

	numTestCases := pr.ReadInt()

	if numTestCases < 1 {
		panic(fmt.Errorf("no testcases available"))
	}

	for testIndex := 1; testIndex <= numTestCases; testIndex++ {
		d := parse(pr, testIndex)
		solve(pr, d)
	}

	pr.Close()
}

示例#10
文件: mattermost.go 项目: lfbrock/platform

func cmdAssignRole() {
	if flagCmdAssignRole {
		if len(flagEmail) == 0 {
			fmt.Fprintln(os.Stderr, "flag needs an argument: -email")
			flag.Usage()
			os.Exit(1)
		}

		if !model.IsValidUserRoles(flagRole) {
			fmt.Fprintln(os.Stderr, "flag invalid argument: -role")
			flag.Usage()
			os.Exit(1)
		}

		c := getMockContext()

		var user *model.User
		if result := <-api.Srv.Store.User().GetByEmail(flagEmail); result.Err != nil {
			l4g.Error("%v", result.Err)
			flushLogAndExit(1)
		} else {
			user = result.Data.(*model.User)
		}

		if !user.IsInRole(flagRole) {
			api.UpdateUserRoles(c, user, flagRole)
		}

		os.Exit(0)
	}
}

示例#11
文件: main.go 项目: mohae/peu

func realMain() int {
	flag.Parse()
	if help {
		flag.Usage()
		fmt.Fprint(os.Stderr, "Flags:\n")
		fmt.Fprint(os.Stderr, "\n")
		flag.PrintDefaults()
		return 0
	}

	worker.files = flag.Args() // this is the list of files
	if len(worker.files) == 0 {
		flag.Usage()
		return 1
	}
	err := worker.Work()
	if err != nil {
		if err == ErrProcess {
			return len(worker.errs) // the number of operations (files) that errored is the return code
		}
		return 1
	}

	return 0
}

示例#12
文件: mattermost.go 项目: lfbrock/platform

func cmdCreateTeam() {
	if flagCmdCreateTeam {
		if len(flagTeamName) == 0 {
			fmt.Fprintln(os.Stderr, "flag needs an argument: -team_name")
			flag.Usage()
			os.Exit(1)
		}

		if len(flagEmail) == 0 {
			fmt.Fprintln(os.Stderr, "flag needs an argument: -email")
			flag.Usage()
			os.Exit(1)
		}

		c := getMockContext()

		team := &model.Team{}
		team.DisplayName = flagTeamName
		team.Name = flagTeamName
		team.Email = flagEmail
		team.Type = model.TEAM_OPEN

		api.CreateTeam(c, team)
		if c.Err != nil {
			if c.Err.Id != "store.sql_team.save.domain_exists.app_error" {
				l4g.Error("%v", c.Err)
				flushLogAndExit(1)
			}
		}

		os.Exit(0)
	}
}

示例#13
文件: echoserver.go 项目: ammarar/DecentralizedLoadBalancer

func main() {
	var ihelp *bool = flag.Bool("h", false, "Print help information")
	var iport *int = flag.Int("p", 6666, "Port number")
	var iverb *int = flag.Int("v", 1, "Verbosity (0-6)")
	var idrop *int = flag.Int("r", 0, "Network packet drop percentage")
	var elim *int = flag.Int("k", 5, "Epoch limit")
	var ems *int = flag.Int("d", 2000, "Epoch duration (millisecconds)")
	flag.Parse()
	if *ihelp {
		flag.Usage()
		os.Exit(0)
	}
	var port int = *iport
	if flag.NArg() > 0 {
		nread, _ := fmt.Sscanf(flag.Arg(0), "%d", &port)
		if nread != 1 {
			flag.Usage()
			os.Exit(0)
		}
	}
	params := &lsp12.LspParams{*elim, *ems}

	lsplog.SetVerbose(*iverb)
	lspnet.SetWriteDropPercent(*idrop)
	fmt.Printf("Establishing server on port %d\n", port)
	srv, err := lsp12.NewLspServer(port, params)
	if err != nil {
		fmt.Printf("... failed.  Error message %s\n", err.Error())
	} else {
		runserver(srv)
	}
}

示例#14
文件: terminate.go 项目: 135yshr/goracom

func main() {
	flag.Parse()

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

	if flag.NArg() != 2 {
		flag.Usage()
		os.Exit(-1)
	}
	imsi := flag.Arg(0)
	protection := flag.Arg(1)

	c, err := goracom.NewClient(email, password)
	errToExit(err)
	s := c.NewSubscriber()
	if protection == "false" {
		sub, err := s.EnableTerminate(imsi)
		errToExit(err)
		printSubscriber(*sub)
	} else {
		sub, err := s.DisableTerminate(imsi)
		errToExit(err)
		printSubscriber(*sub)
	}
}

示例#15
文件: main.go 项目: iovisor/iomodules

func main() {
	flag.Parse()
	if helpFlag {
		flag.Usage()
		os.Exit(0)
	}
	if len(upstreamUrl) == 0 {
		fmt.Println("Missing argument -upstream")
		flag.Usage()
		os.Exit(1)
	}
	if len(dataplaneUrl) == 0 {
		fmt.Println("Missing argument -dataplane")
		flag.Usage()
		os.Exit(1)
	}
	notifier := gbp.NewNotifier(upstreamUrl, listenSocket)
	if err := notifier.NotifyEndpointUp(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	g, err := gbp.NewServer(upstreamUrl, dataplaneUrl)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	gbp.Info.Printf("GBP Server listening on %s\n", listenSocket)
	http.ListenAndServe(listenSocket, g.Handler())
}

示例#16
文件: main.go 项目: jmptrader/esdb

func main() {
	log.SetFlags(0)

	flag.Parse()

	// Set the data directory.
	if flag.NArg() == 0 {
		flag.Usage()
		log.Fatal("Data path argument required")
	}

	if *stop == 0 {
		flag.Usage()
		log.Fatal("stop commit is required")
	}

	dbpath := flag.Arg(0)

	client := cluster.NewLocalClient("http://"+*node, 1)

	meta, err := client.StreamsMetadata()
	if err != nil {
		log.Fatal(err)
	}

	err = cluster.Clear(dbpath, *stop, meta.Closed)
	if err != nil {
		log.Fatal(err)
	}
}

示例#17
文件: set_tag.go 项目: 135yshr/goracom

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

示例#18
文件: sssaas-cli.go 项目: SSSaaS/sssaas-cli

func main() {
	create := flag.Bool("create", false, "create shares from a secret")
	minimum := flag.Int("minimum", 3, "minimum shares required to recreate secret")
	shares := flag.Int("shares", 4, "total shares to create (shares >= minimum)")
	secret := flag.String("secret", "Hello, World!", "secret to share")
	combine := flag.Bool("combine", false, "combines shares into a secret")
	raw := flag.String("secrets", "", "comma separated list of shared secrets")

	flag.Parse()

	if *create == *combine {
		flag.Usage()
	} else if *create {
		if *minimum > *shares {
			flag.Usage()
		} else {
			values := sssa.Create(*minimum, *shares, *secret)
			for i := range values {
				fmt.Println(values[i])
			}
		}
	} else {
		if *raw == "" {
			flag.Usage()
		} else {
			secrets := strings.Split(*raw, ",")
			value := sssa.Combine(secrets)
			fmt.Println("Secret: ", value)
		}
	}
}

示例#19
文件: expiry_time.go 项目: 135yshr/goracom

func main() {
	flag.Parse()

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

	if flag.NArg() != 2 {
		flag.Usage()
		os.Exit(-1)
	}
	imsi := flag.Arg(0)
	tm, err := strconv.ParseInt(flag.Arg(1), 10, 64)
	if err != nil {
		fmt.Printf("%s\n\n", err.Error())
		flag.Usage()
		os.Exit(-1)
	}

	c, err := goracom.NewClient(email, password)
	errToExit(err)
	s := c.NewSubscriber()
	if tm == 0 {
		sub, err := s.UnsetExpiryTime(imsi)
		errToExit(err)
		printSubscriber(*sub)
	} else {
		sub, err := s.SetExpiryTime(imsi, tm)
		errToExit(err)
		printSubscriber(*sub)
	}
}

示例#20
文件: length-heat-annot.go 项目: henmt/2015

func init() {
	flag.StringVar(&in, "in", "", "file name of a BAM file to be processed.")
	flag.StringVar(&annot, "annot", "", "file name of a GFF file containing annotations.")
	flag.Var(&classes, "class", "comma separated set of annotation classes to analyse.")
	flag.StringVar(&out, "out", "", "outfile name.")
	flag.IntVar(&minLength, "min", 20, "minimum length read considered.")
	flag.IntVar(&maxLength, "max", 35, "maximum length read considered.")
	flag.IntVar(&minId, "minid", 90, "minimum percentage identity for non-clipped bases.")
	flag.IntVar(&minQ, "minQ", 20, "minimum per-base sequence quality.")
	flag.IntVar(&filter, "f", 0, "filter on piwi type 0: no filter, 1: primary, 2: secondary.")
	flag.Float64Var(&minAvQ, "minAvQ", 30, "minimum average per-base sequence quality.")
	flag.IntVar(&mapQ, "mapQ", 0, "minimum mapping quality [0, 255).")
	flag.IntVar(&binLength, "bin", 1e7, "bin length.")
	flag.StringVar(&format, "format", "svg", "specifies the output format of the example: eps, jpg, jpeg, pdf, png, svg, and tiff.")
	help := flag.Bool("help", false, "output this usage message.")
	flag.Parse()
	mapQb = byte(mapQ)
	if *help {
		flag.Usage()
		os.Exit(0)
	}
	if in == "" || out == "" || annot == "" || len(classes) == 0 || mapQ < 0 || mapQ > 254 {
		flag.Usage()
		os.Exit(1)
	}
	for _, s := range []string{"eps", "jpg", "jpeg", "pdf", "png", "svg", "tiff"} {
		if format == s {
			return
		}
	}
	flag.Usage()
	os.Exit(1)
}

示例#21
文件: main.go 项目: srinathh/staticserver

func main() {

	var ipport string

	flag.StringVar(&ipport, "http", "127.0.0.1:8080", "The IP address and port to host the server at")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage: staticserver -flags <directory to serve>\n")
		flag.PrintDefaults()
	}

	flag.Parse()

	if flag.NArg() != 1 {
		fmt.Fprintf(os.Stderr, "Error: You must specify a target directory to serve\n")
		flag.Usage()
		return
	}

	server, err := staticserver.NewStaticServer(flag.Arg(0))
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error: %s\n", err)
		flag.Usage()
		return
	}

	http.ListenAndServe(ipport, server)
}

示例#22
文件: cbfsclient.go 项目: smallsweet/cbfs

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

示例#23
文件: cheerio.go 项目: pombredanne/cheerio

func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage: %s <command> [command-opts]\n", os.Args[0])
		fmt.Fprintln(os.Stderr, "Commands:")
		for cmd, _ := range Commands {
			fmt.Fprintf(os.Stderr, "  %s\n", cmd)
		}
	}
	flag.Parse()
	if flag.NArg() < 1 {
		flag.Usage()
		os.Exit(1)
	}

	subcommand := flag.Arg(0)

	if cmd, in := Commands[subcommand]; in {
		flags := flag.NewFlagSet(Cmd_Repo, flag.ExitOnError)
		cmd(os.Args[1:], flags)
		os.Exit(0)
	}

	fmt.Fprintf(os.Stderr, "Subcommand not recognized: %s\n", flag.Arg(0))
	flag.Usage()
	os.Exit(1)
}

示例#24
文件: main.go 项目: jamesandariese/issh

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

示例#25
文件: main.go 项目: TobiasBales/goose

func main() {

	flag.Usage = usage
	flag.Parse()

	args := flag.Args()
	if len(args) == 0 || args[0] == "-h" {
		flag.Usage()
		return
	}

	var cmd *Command
	name := args[0]
	for _, c := range commands {
		if strings.HasPrefix(c.Name, name) {
			cmd = c
			break
		}
	}

	if cmd == nil {
		fmt.Printf("error: unknown command %q\n", name)
		flag.Usage()
		os.Exit(1)
	}

	cmd.Exec(args[1:])
}

示例#26
文件: gorazor.go 项目: Comdex/gorazor

func main() {
	debug := false
	flag.Usage = Usage

	flag.Parse()
	options := gorazor.Option{}
	if debug {
		options["Debug"] = true
	}

	if flag.NArg() == 2 {
		arg1, arg2 := flag.Arg(0), flag.Arg(1)
		stat, err := os.Stat(arg1)
		if err != nil {
			fmt.Println(err)
			os.Exit(2)
		}
		if stat.IsDir() {
			fmt.Printf("Processing dir: %s %s\n", arg1, arg2)
			err := gorazor.GenFolder(arg1, arg2, options)
			if err != nil {
				fmt.Println(err)
			}
		} else if stat.Mode().IsRegular() {
			fmt.Printf("Processing file: %s %s\n", arg1, arg2)
			gorazor.GenFile(arg1, arg2, options)
		} else {
			flag.Usage()
		}
	} else {
		flag.Usage()
	}

}

示例#27
文件: update_speed.go 项目: 135yshr/goracom

func main() {
	flag.Parse()

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

	if flag.NArg() != 2 {
		flag.Usage()
		os.Exit(-1)
	}
	imsi := flag.Arg(0)
	speed := flag.Arg(1)

	c, err := goracom.NewClient(email, password)
	errToExit(err)
	s := c.NewSubscriber()

	if sub, err := s.UpdateSpeedClass(imsi, speed); err == nil {
		printSubscriber(*sub)
	} else {
		errToExit(err)
	}
}

示例#28
文件: gur.go 项目: sbinet/gur

// Program entry
func main() {
	flag.Parse()
	flag.Usage = printDefaults
	if *isHelp {
		flag.Usage()
		os.Exit(0)
	}
	if *isTest {
		test()
		return
	}
	if *isDownload {
		if len(flag.Args()) == 0 {
			err := errors.New("no packages specified")
			handleError(err)
		}
		readCache()
		checkDepends(flag.Arg(0))
		download(flag.Arg(0))
		return
	}
	if *isSearch {
		search()
		return
	}
	flag.Usage()
}

示例#29
文件: client.go 项目: supersid/gotunnel

func main() {
	flag.Usage = Usage
	flag.Parse()

	if *port == "" || *remote == "" {
		flag.Usage()
		os.Exit(1)
	}

	if !*skipVerCheck {
		if vercheck.HasMinorUpdate(
			"https://raw.github.com/ciju/gotunnel/master/VERSION",
			"./VERSION",
		) {
			l.Info("\nNew version of Gotunnel is available. Please update your code and run again. Or start with option -sc to continue with this version.\n")
			os.Exit(0)
		}
	}

	servInfo := make(chan string)

	go func() {
		serverat := <-servInfo
		fmt.Printf("Your site should be available at: \033[1;34m%s\033[0m\n", serverat)
	}()

	if !gtclient.SetupClient(*port, *remote, *subdomain, servInfo) {
		flag.Usage()
		os.Exit(1)
	} else {
		os.Exit(0)
	}
}

示例#30
文件: main.go 项目: rwcarlsen/cloudlus

func main() {
	log.SetFlags(0)
	flag.Usage = func() {
		log.Printf("Usage: cloudlus [OPTION] <subcommand> [OPTION] [args]\n")
		flag.PrintDefaults()
		log.Printf("Subcommands:\n")
		for cmd, _ := range cmds {
			log.Printf("  %v", cmd)
		}
	}
	flag.Parse()

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

	cmd, ok := cmds[flag.Arg(0)]
	if !ok {
		flag.Usage()
		return
	}

	cmd(flag.Arg(0), flag.Args()[1:])
}

展开阅读全文