本文整理匯總了Golang中github.com/codegangsta/cli.Context.GlobalInt方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.GlobalInt方法的具體用法?Golang Context.GlobalInt怎麽用?Golang Context.GlobalInt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/codegangsta/cli.Context
的用法示例。
在下文中一共展示了Context.GlobalInt方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: processGlobalFlags
func processGlobalFlags(c *cli.Context) time.Duration {
var network string
if c.GlobalBool("tcp") {
network = "tcp"
} else {
network = "udp"
}
client, err := raidman.Dial(network, fmt.Sprintf("%s:%d", c.GlobalString("host"), c.GlobalInt("port")))
if c.GlobalString("event-host") == "nil" {
log.Panic("Failed to automatically get the hostname. Please specify it with --host")
}
if err != nil {
log.Panicf("Failed to connect to the riemann host because %s", err)
}
attribute, err := processAttributes(c.GlobalStringSlice("attribute"))
if err != nil {
log.Panic(err)
}
eventTemplate := raidman.Event{
Ttl: float32(c.GlobalDuration("ttl").Seconds()),
Tags: c.GlobalStringSlice("tags"),
Host: c.GlobalString("event-host"),
Attributes: attribute,
}
riemannSend = func(url, method string, duration float64) {
event := eventTemplate
event.Service = fmt.Sprintf("%s %s", url, method)
event.Time = time.Now().Unix()
event.Metric = duration
client.Send(&event)
}
return c.GlobalDuration("interval")
}
示例2: MakeChain
// MakeChain creates a chain manager from set command line flags.
func MakeChain(ctx *cli.Context) (chain *core.BlockChain, chainDb ethdb.Database) {
datadir := MustMakeDataDir(ctx)
cache := ctx.GlobalInt(CacheFlag.Name)
handles := MakeDatabaseHandles()
var err error
if chainDb, err = ethdb.NewLDBDatabase(filepath.Join(datadir, "chaindata"), cache, handles); err != nil {
Fatalf("Could not open database: %v", err)
}
if ctx.GlobalBool(OlympicFlag.Name) {
_, err := core.WriteTestNetGenesisBlock(chainDb)
if err != nil {
glog.Fatalln(err)
}
}
eventMux := new(event.TypeMux)
pow := ethash.New()
//genesis := core.GenesisBlock(uint64(ctx.GlobalInt(GenesisNonceFlag.Name)), blockDB)
chain, err = core.NewBlockChain(chainDb, pow, eventMux)
if err != nil {
Fatalf("Could not start chainmanager: %v", err)
}
return chain, chainDb
}
示例3: cliStart
func cliStart(c *cli.Context) {
config := nomadapi.DefaultConfig()
config.Address = c.GlobalString("nomad-address")
config.Region = c.GlobalString("nomad-region")
config.WaitTime = time.Duration(c.GlobalInt("wait-time")) * time.Second
client, err := nomadapi.NewClient(config)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
log := logrus.New()
level, err := logrus.ParseLevel(c.GlobalString("log-level"))
if err != nil {
fmt.Println("incorrect log-level")
os.Exit(2)
}
log.Out = os.Stderr
log.Level = level
usage := usage.NewUsage(client, time.Duration(c.GlobalInt("wait-time"))*time.Second, log)
usage.Loop()
context := api.NewContext(c.GlobalString("api-addr"), serviceVersion, usage, log, client)
log.Fatal(api.ListenAndServe(context))
}
示例4: startNode
// startNode boots up the system node and all registered protocols, after which
// it unlocks any requested accounts, and starts the RPC/IPC interfaces and the
// miner.
func startNode(ctx *cli.Context, stack *node.Node) {
// Start up the node itself
utils.StartNode(stack)
// Unlock any account specifically requested
var ethereum *eth.Ethereum
if err := stack.Service(ðereum); err != nil {
utils.Fatalf("ethereum service not running: %v", err)
}
accman := ethereum.AccountManager()
passwords := utils.MakePasswordList(ctx)
accounts := strings.Split(ctx.GlobalString(utils.UnlockedAccountFlag.Name), ",")
for i, account := range accounts {
if trimmed := strings.TrimSpace(account); trimmed != "" {
unlockAccount(ctx, accman, trimmed, i, passwords)
}
}
// Start auxiliary services if enabled
if ctx.GlobalBool(utils.MiningEnabledFlag.Name) {
if err := ethereum.StartMining(ctx.GlobalInt(utils.MinerThreadsFlag.Name), ctx.GlobalString(utils.MiningGPUFlag.Name)); err != nil {
utils.Fatalf("Failed to start mining: %v", err)
}
}
}
示例5: storagepoolAgent
func storagepoolAgent(c *cli.Context) {
healthCheckInterval := c.GlobalInt("healthcheck-interval")
healthCheckBaseDir := c.GlobalString("healthcheck-basedir")
healthCheckType := c.String("storagepool-healthcheck-type")
cattleUrl := c.GlobalString("url")
cattleAccessKey := c.GlobalString("access-key")
cattleSecretKey := c.GlobalString("secret-key")
if c.GlobalBool("debug") {
log.SetLevel(log.DebugLevel)
}
storagepoolRootDir := c.GlobalString("storagepool-rootdir")
driver := c.GlobalString("storagepool-driver")
if driver == "" {
log.Fatal("required field storagepool-driver has not been set")
}
cattleClient, err := cattle.NewCattleClient(cattleUrl, cattleAccessKey, cattleSecretKey)
if err != nil {
log.Fatal(err)
}
storagepoolAgent := NewStoragepoolAgent(healthCheckInterval, storagepoolRootDir, driver, healthCheckBaseDir, healthCheckType, cattleClient)
metadataUrl := c.String("storagepool-metadata-url")
if err := storagepoolAgent.Run(metadataUrl); err != nil {
log.Fatal(err)
}
}
示例6: startEth
func startEth(ctx *cli.Context, eth *eth.Ethereum) {
// Start Ethereum itself
utils.StartEthereum(eth)
am := eth.AccountManager()
account := ctx.GlobalString(utils.UnlockedAccountFlag.Name)
accounts := strings.Split(account, " ")
for i, account := range accounts {
if len(account) > 0 {
if account == "primary" {
utils.Fatalf("the 'primary' keyword is deprecated. You can use integer indexes, but the indexes are not permanent, they can change if you add external keys, export your keys or copy your keystore to another node.")
}
unlockAccount(ctx, am, account, i)
}
}
// Start auxiliary services if enabled.
if !ctx.GlobalBool(utils.IPCDisabledFlag.Name) {
if err := utils.StartIPC(eth, ctx); err != nil {
utils.Fatalf("Error string IPC: %v", err)
}
}
if ctx.GlobalBool(utils.RPCEnabledFlag.Name) {
if err := utils.StartRPC(eth, ctx); err != nil {
utils.Fatalf("Error starting RPC: %v", err)
}
}
if ctx.GlobalBool(utils.MiningEnabledFlag.Name) {
if err := eth.StartMining(ctx.GlobalInt(utils.MinerThreadsFlag.Name)); err != nil {
utils.Fatalf("%v", err)
}
}
}
示例7: load
// fetch data for subreddits based on configuration provided
func load(configuration *Configuration, context *cli.Context) {
timeout := time.Duration(context.GlobalInt("timeout"))
jsonOut := context.GlobalBool("json")
browserOut := context.GlobalBool("browser")
port := context.GlobalString("port")
if len(configuration.Subreddits) == 0 {
log.Fatalln("No subreddits found")
}
results := make(chan *Subreddit, len(configuration.Subreddits))
for _, subreddit := range configuration.Subreddits {
go fetch(subreddit, results)
}
collect(results, configuration, timeout)
if browserOut {
browserOutput(configuration.Subreddits, port)
} else if jsonOut {
jsonOutput(configuration.Subreddits)
} else {
prettyOutput(configuration.Subreddits)
}
}
示例8: CheckCommonFlags
// As CheckCommonFlagsAndInit, but will return all parsed and verified common values, including an optional error
func CheckCommonFlags(c *cli.Context) (nr int, level api.Importance, filters []api.FileFilter, err error) {
// Put parsed args in cmd and sanitize it
nr = c.GlobalInt(StreamsPerInputDeviceFlagName)
if nr < 1 {
return 0, level, filters, fmt.Errorf("--%v must not be smaller than 1", StreamsPerInputDeviceFlagName)
}
level, err = api.ParseImportance(c.GlobalString(LogLevelFlagName))
if err != nil {
return
}
filterStr := c.GlobalString(FileExcludePatternFlagName)
for _, fstr := range strings.Split(filterStr, ",") {
if f, e := api.ParseFileFilter(fstr); e != nil {
err = e
return
} else {
filters = append(filters, f)
}
}
err = parseAdditionalFlags(c)
return
}
示例9: MakeChain
// MakeChain creates a chain manager from set command line flags.
func MakeChain(ctx *cli.Context) (chain *core.ChainManager, chainDb common.Database) {
datadir := ctx.GlobalString(DataDirFlag.Name)
cache := ctx.GlobalInt(CacheFlag.Name)
var err error
if chainDb, err = ethdb.NewLDBDatabase(filepath.Join(datadir, "chaindata"), cache); err != nil {
Fatalf("Could not open database: %v", err)
}
if ctx.GlobalBool(OlympicFlag.Name) {
InitOlympic()
_, err := core.WriteTestNetGenesisBlock(chainDb, 42)
if err != nil {
glog.Fatalln(err)
}
}
eventMux := new(event.TypeMux)
pow := ethash.New()
//genesis := core.GenesisBlock(uint64(ctx.GlobalInt(GenesisNonceFlag.Name)), blockDB)
chain, err = core.NewChainManager(chainDb, nil, pow, eventMux)
if err != nil {
Fatalf("Could not start chainmanager: %v", err)
}
proc := core.NewBlockProcessor(chainDb, pow, chain, eventMux)
chain.SetProcessor(proc)
return chain, chainDb
}
示例10: sftpSetup
func sftpSetup(c *cli.Context) (connector.Connection, error) {
var (
password *string
privateKeyFilepath *string
)
host := c.GlobalString("sftp-host")
port := c.GlobalInt("sftp-port")
remotePath := c.GlobalString("sftp-remote-path")
username := c.GlobalString("sftp-username")
passwordInput := os.Getenv("ARQ_SFTP_PASSWORD")
if passwordInput != "" {
password = &passwordInput
} else {
password = nil
}
if c.GlobalIsSet("sftp-private-key-filepath") {
privateKey := c.GlobalString("sftp-private-key-filepath")
privateKeyFilepath = &privateKey
} else {
privateKeyFilepath = nil
}
cacheDirectory := c.GlobalString("cache-directory")
connection, err := connector.NewSFTPConnection(host, port, remotePath,
username, password, privateKeyFilepath, cacheDirectory)
if err != nil {
log.Errorf("Error while establishing SFTP connection: %s", err)
return connector.SFTPConnection{}, err
}
return *connection, nil
}
示例11: MakeChain
// MakeChain creates a chain manager from set command line flags.
func MakeChain(ctx *cli.Context) (chain *core.ChainManager, blockDB, stateDB, extraDB common.Database) {
dd := ctx.GlobalString(DataDirFlag.Name)
var err error
if blockDB, err = ethdb.NewLDBDatabase(filepath.Join(dd, "blockchain")); err != nil {
Fatalf("Could not open database: %v", err)
}
if stateDB, err = ethdb.NewLDBDatabase(filepath.Join(dd, "state")); err != nil {
Fatalf("Could not open database: %v", err)
}
if extraDB, err = ethdb.NewLDBDatabase(filepath.Join(dd, "extra")); err != nil {
Fatalf("Could not open database: %v", err)
}
eventMux := new(event.TypeMux)
pow := ethash.New()
genesis := core.GenesisBlock(uint64(ctx.GlobalInt(GenesisNonceFlag.Name)), blockDB)
chain, err = core.NewChainManager(genesis, blockDB, stateDB, pow, eventMux)
if err != nil {
Fatalf("Could not start chainmanager: %v", err)
}
proc := core.NewBlockProcessor(stateDB, extraDB, pow, chain, eventMux)
chain.SetProcessor(proc)
return chain, blockDB, stateDB, extraDB
}
示例12: init
func (cli *CLI) init(ctx *cli.Context) error {
if ctx.GlobalBool("prtg") {
cli.Err, cli.Out = prtg.Err, prtg.Out
}
var err error
if cli.cred, err = cli.Store.Load(); err == nil {
cli.c, err = cli.Client(cli.cred.URL, cli.cred.User, cli.cred.Pass)
}
if err != nil {
cli.cred = &Creds{ctx.GlobalString("addr"), ctx.GlobalString("user"), ctx.GlobalString("pass")}
if cli.c, err = cli.Client(cli.cred.URL, cli.cred.User, cli.cred.Pass); err != nil {
return err
}
}
a, p, s, o := ctx.GlobalString("agent"), ctx.GlobalString("project"), ctx.GlobalString("stage"), ctx.GlobalString("output")
if cli.a, err = regexp.Compile(a); err != nil {
return err
}
if cli.p, err = regexp.Compile(p); err != nil {
return err
}
if cli.s, err = regexp.Compile(s); err != nil {
return err
}
if cli.o, err = regexp.Compile(o); err != nil {
return err
}
if cli.d, err = time.ParseDuration(ctx.GlobalString("timeout")); err != nil {
return err
}
cli.n, cli.rev = int64(ctx.GlobalInt("build")), ctx.GlobalString("revision")
cli.c.SetTimeout(cli.d)
return nil
}
示例13: StartAPIServer
//Initialize the Siil API server
func StartAPIServer(c *cli.Context) {
var (
baseRouter *mux.Router
port int = c.GlobalInt("port")
tmplDir string = fmt.Sprintf("%s/templates", c.GlobalString("wd"))
)
fmt.Printf("Starting API server on port %d...\n", port)
if err := entity.CreateConnection(c.GlobalString("mysql")); err != nil {
log.Fatal(err)
}
fmt.Println("Loading templates...")
if t, err := ioutil.ReadDir(tmplDir); err != nil {
log.Fatal(err)
} else {
for _, file := range t {
name := fmt.Sprintf("%s/%s", tmplDir, file.Name())
if template, err := raymond.ParseFile(name); err != nil {
log.Panic(err)
} else {
templates[file.Name()] = template
}
}
}
site.SIIL_SITE_ID = c.GlobalString("sid")
baseRouter = mux.NewRouter()
//Root endpoint doesn't really do anything
baseRouter.HandleFunc("/", handleRootRequest)
baseRouter.HandleFunc("/success", handleSuccessRequest)
baseRouter.HandleFunc("/fail", handleCancelRequest)
//User primer & authentication handlers
baseRouter.HandleFunc("/signin/{site:[a-zA-Z0-9]*}", handleSigninRequest)
baseRouter.HandleFunc("/id/{site:[a-zA-Z0-9]*}", handleSessionCreation)
//New site creation
baseRouter.HandleFunc("/addsite", handleAddSiteForm)
baseRouter.HandleFunc("/addsite/fail", handleAddSiteFormFailed)
baseRouter.HandleFunc("/addsite/success", handleAddSiteSuccess)
baseRouter.HandleFunc("/addsite/request", handleAddSiteRequest)
//Edit site
baseRouter.HandleFunc("/editsite/success", handleEditSiteSuccess)
baseRouter.HandleFunc("/editsite/{site:[a-zA-Z0-9]*}", handleEditSiteForm)
baseRouter.HandleFunc("/editsite/{site:[a-zA-Z0-9]*}/fail", handleEditSiteFormFailed)
baseRouter.HandleFunc("/editsite/{site:[a-zA-Z0-9]*}/request", handleEditSiteRequest)
//Invalidate sessions
baseRouter.HandleFunc("/signout/{token:[a-zA-Z0-9]*}", handleSignoutRequest)
baseRouter.HandleFunc("/api/session", handleAPISessionRequest)
baseRouter.HandleFunc("/api/me", handleAPIMeRequest)
http.ListenAndServe(fmt.Sprintf(":%d", port), baseRouter)
}
示例14: SetupVM
// SetupVM configured the VM package's global settings
func SetupVM(ctx *cli.Context) {
vm.EnableJit = ctx.GlobalBool(VMEnableJitFlag.Name)
vm.ForceJit = ctx.GlobalBool(VMForceJitFlag.Name)
vm.SetJITCacheSize(ctx.GlobalInt(VMJitCacheFlag.Name))
if ctx.GlobalIsSet(VMDebugFlag.Name) {
vm.Debug = ctx.GlobalBool(VMDebugFlag.Name)
}
}
示例15: version
func version(c *cli.Context) {
fmt.Println(clientIdentifier)
fmt.Println("Version:", verString)
fmt.Println("Protocol Versions:", eth.ProtocolVersions)
fmt.Println("Network Id:", c.GlobalInt(utils.NetworkIdFlag.Name))
fmt.Println("Go Version:", runtime.Version())
fmt.Println("OS:", runtime.GOOS)
fmt.Printf("GOPATH=%s\n", os.Getenv("GOPATH"))
fmt.Printf("GOROOT=%s\n", runtime.GOROOT())
}