本文整理汇总了Golang中github.com/codegangsta/cli.Context.Int方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Int方法的具体用法?Golang Context.Int怎么用?Golang Context.Int使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/codegangsta/cli.Context
的用法示例。
在下文中一共展示了Context.Int方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DropletBackups
// Backups returns a list of backup images for a droplet.
func DropletBackups(c *cli.Context) {
client := NewClient(c, DefaultConfig)
id := c.Int(ArgDropletID)
opts := LoadOpts(c)
f := func(opt *godo.ListOptions) ([]interface{}, *godo.Response, error) {
list, resp, err := client.Droplets.Backups(id, opt)
if err != nil {
return nil, nil, err
}
si := make([]interface{}, len(list))
for i := range list {
si[i] = list[i]
}
return si, resp, err
}
si, err := PaginateResp(f, opts)
if err != nil {
logrus.WithField("err", err).Fatal("could not list backups for droplet")
}
list := make([]godo.Image, len(si))
for i := range si {
list[i] = si[i].(godo.Image)
}
err = displayOutput(c, list)
if err != nil {
logrus.WithField("err", err).Fatal("could not write output")
}
}
示例2: NewDriver
// NewDriver creates a new MACVLAN Driver
func NewDriver(version string, ctx *cli.Context) (*Driver, error) {
docker, err := dockerclient.NewDockerClient("unix:///var/run/docker.sock", nil)
if err != nil {
return nil, fmt.Errorf("could not connect to docker: %s", err)
}
// lower bound of v4 MTU is 68-bytes per rfc791
if ctx.Int("mtu") <= 0 {
cliMTU = defaultMTU
} else if ctx.Int("mtu") >= minMTU {
cliMTU = ctx.Int("mtu")
} else {
log.Fatalf("The MTU value passed [ %d ] must be greater than [ %d ] bytes per rfc791", ctx.Int("mtu"), minMTU)
}
// Set the default mode to bridge
if ctx.String("mode") == "" {
macvlanMode = bridgeMode
}
switch ctx.String("mode") {
case bridgeMode:
macvlanMode = bridgeMode
// todo: in other modes if relevant
}
d := &Driver{
networks: networkTable{},
dockerer: dockerer{
client: docker,
},
}
return d, nil
}
示例3: server
func server(ctx *cli.Context) {
port := ctx.Int("port")
s := apidemic.NewServer()
log.Println("starting server on port :", port)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), s))
}
示例4: FromCLIContext
// FromCLIContext creates a Config using a cli.Context by pulling configuration
// from the flags in the context.
func FromCLIContext(c *cli.Context) *Config {
cfg := &Config{}
cfgVal := reflect.ValueOf(cfg).Elem()
for _, def := range defs {
if !def.HasField {
continue
}
field := cfgVal.FieldByName(def.FieldName)
if _, ok := def.Flag.(*cli.BoolFlag); ok {
field.SetBool(c.Bool(def.Name))
} else if _, ok := def.Flag.(*cli.DurationFlag); ok {
field.Set(reflect.ValueOf(c.Duration(def.Name)))
} else if _, ok := def.Flag.(*cli.IntFlag); ok {
field.SetInt(int64(c.Int(def.Name)))
} else if _, ok := def.Flag.(*cli.StringFlag); ok {
field.SetString(c.String(def.Name))
}
}
cfg.ProviderConfig = ProviderConfigFromEnviron(cfg.ProviderName)
return cfg
}
示例5: health
func health(c *cli.Context) {
endpoint := c.String("e")
requests := c.Int("r")
done := make(chan bool)
var healthy uint64 = 0
for i := 0; i < requests; i++ {
go func() {
resp, err := http.Get("http://" + endpoint + "/health")
if err != nil {
fmt.Printf("ERROR: %v\n", err)
} else {
fmt.Printf("Response: %v\n", resp.Status)
if resp.StatusCode == 200 {
atomic.AddUint64(&healthy, 1)
runtime.Gosched()
}
}
done <- true
}()
}
for i := 0; i < requests; i++ {
<-done
}
fmt.Printf("Healthy Requests: %v\n", atomic.LoadUint64(&healthy))
}
示例6: createNetwork
func createNetwork(ctx *cli.Context) {
argCheck(1, ctx)
subnet := ctx.String("subnet")
gateway := ctx.String("gateway")
if subnet == "" || gateway == "" {
errExit(ctx, exitHelp, "Invalid Arguments", true)
}
tenant := ctx.String("tenant")
network := ctx.Args()[0]
encap := ctx.String("encap")
pktTag := ctx.Int("pkt-tag")
url := fmt.Sprintf("%s%s:%s/", networkURL(ctx), tenant, network)
out := map[string]interface{}{
"tenantName": tenant,
"networkName": network,
"encap": encap,
"pktTag": pktTag,
"subnet": subnet,
"gateway": gateway,
}
postMap(ctx, url, out)
}
示例7: getMetric
func getMetric(ctx *cli.Context) error {
if !ctx.IsSet("metric-namespace") {
return newUsageError("namespace is required\n\n", ctx)
}
ns := ctx.String("metric-namespace")
ver := ctx.Int("metric-version")
metric := pClient.GetMetric(ns, ver)
switch mtype := metric.(type) {
case []*client.GetMetricResult:
// Multiple metrics
var merr error
for i, m := range metric.([]*client.GetMetricResult) {
err := printMetric(m, i)
if err != nil {
merr = err
}
}
if merr != nil {
return merr
}
case *client.GetMetricResult:
// Single metric
err := printMetric(metric.(*client.GetMetricResult), 0)
if err != nil {
return err
}
default:
return fmt.Errorf("Unexpected response type %T\n", mtype)
}
return nil
}
示例8: Populate
// Populate updates the specified project context based on command line arguments and subcommands.
func Populate(context *project.Context, c *cli.Context) {
context.ComposeFiles = c.GlobalStringSlice("file")
if len(context.ComposeFiles) == 0 {
context.ComposeFiles = []string{"docker-compose.yml"}
if _, err := os.Stat("docker-compose.override.yml"); err == nil {
context.ComposeFiles = append(context.ComposeFiles, "docker-compose.override.yml")
}
}
context.ProjectName = c.GlobalString("project-name")
if c.Command.Name == "logs" {
context.Log = true
context.FollowLog = c.Bool("follow")
} else if c.Command.Name == "up" || c.Command.Name == "create" {
context.Log = !c.Bool("d")
context.NoRecreate = c.Bool("no-recreate")
context.ForceRecreate = c.Bool("force-recreate")
context.NoBuild = c.Bool("no-build")
} else if c.Command.Name == "stop" || c.Command.Name == "restart" || c.Command.Name == "scale" {
context.Timeout = uint(c.Int("timeout"))
} else if c.Command.Name == "kill" {
context.Signal = c.String("signal")
} else if c.Command.Name == "rm" {
context.Volume = c.Bool("v")
} else if c.Command.Name == "build" {
context.NoCache = c.Bool("no-cache")
}
}
示例9: GetAction
func GetAction(c *cli.Context) {
if len(c.Args()) != 2 {
log.Fatal("get s3path localpath")
}
s3path, err := NewS3Path(c.Args().Get(0))
if err != nil {
log.Fatal(err)
}
localpath := c.Args().Get(1)
if localpath == "" {
log.Fatal("get s3path localpath")
}
log.Printf("s3path Bucket:%v Prefix:%v", s3path.Bucket, s3path.Prefix)
parallel := c.Int("parallel")
manager := s3manager.NewDownloader(nil)
d := NewDownloader(s3path, localpath, parallel, manager)
client := s3.New(nil)
params := &s3.ListObjectsInput{Bucket: &s3path.Bucket, Prefix: &s3path.Prefix}
err = client.ListObjectsPages(params, d.eachPage)
if err != nil {
log.Fatal(err)
}
d.Wait()
}
示例10: ListAction
func ListAction(c *cli.Context) {
// Figure out input
if len(c.Args()) < 1 {
cli.ShowCommandHelp(c, c.Command.Name)
return
}
jsonFile := c.Args()[0]
data := FromJSON(GetFileContent(jsonFile))
count := c.Int("count")
threads := data.Threads
if count > len(threads) {
count = len(threads)
}
// Sort by message count
sort.Sort(ByMessage(threads))
// Reverse (top = more)
for i, j := 0, len(threads)-1; i < j; i, j = i+1, j-1 {
threads[i], threads[j] = threads[j], threads[i]
}
threads = threads[:count]
for _, thread := range threads {
fmt.Println(strings.Join(DeleteElementFromSlice(thread.Persons, data.WhoAmI), ", ")+" > Messages:", thread.CountMessages(), "Words:", thread.CountWords())
}
}
示例11: RunServer
func RunServer(c *cli.Context) *Server {
s := new(Server)
s.Host = c.String("bind-addr")
s.Port = c.Int("port")
s.Run()
return s
}
示例12: ServerFromCli
// ServerFromCli uses the cli arguments to configure a server instance
func ServerFromCli(c *cli.Context) *gouncer.Server {
CheckSSL(c)
// Initialize configuration components from cli
core := &gouncer.Core{c.String("hostname"), ":" + c.String("port"), c.Bool("jsonp"), c.String("log")}
ssl := &gouncer.Ssl{c.String("certificate"), c.String("key")}
backend := &gouncer.Backend{
Couchdb: c.String("couchdb"),
Userdb: c.String("userdb"),
Groupdb: c.String("groupdb"),
Memcache: c.StringSlice("memcache"),
Smtp: c.String("smtp"),
}
token := &gouncer.Token{c.String("algorithm"), int32(c.Int("expiration"))}
// Create configuration
cfg := &gouncer.Config{
Core: core,
Ssl: ssl,
Backend: backend,
Token: token,
}
return gouncer.NewServer(cfg)
}
示例13: removeContainers
// delete containers which are not running
func removeContainers(c *cli.Context) {
dry := c.Bool("dry")
exited := c.Bool("exited")
hours := c.Int("hours")
if !exited {
cli.ShowCommandHelp(c, "rm")
fmt.Println("EXAMPLE:")
fmt.Println(" command rm --exited")
return
}
if hours <= 0 {
hours = 24
}
ctx := getUtilContext()
if ctx == nil {
return
}
if exited == true {
ctx.DeleteExitedContainers(dry, hours)
}
return
}
示例14: ParseParam
// log.fatalf will block the process and return errors. so the errors.new can be remove, or fmt.Errorf(). fmz.
// when no param pass, it will not equal "", because i set the value(default) first, fmz.
func ParseParam(ctx *cli.Context) error {
if ctx.String("host-interface") == "" {
log.Fatalf("Required flag [ host-interface ] is missing")
return errors.New("Required flag [ host-interface ] is missing")
}
CliIF = ctx.String("host-interface")
if ctx.String("ip") == "" || ctx.String("gateway") == "" || ctx.String("container-name") == "" {
log.Fatalf("Required flag [ ip or gateway or container-name ] is missing")
return errors.New("Required flag [ ip or gateway or container-name ] is missing")
}
CliIP = ctx.String("ip")
CligwIP = ctx.String("gateway")
CliCName = ctx.String("container-name")
if ctx.Int("mtu") <= 0 {
CliMTU = CliMTU
} else if ctx.Int("mtu") >= minMTU {
CliMTU = ctx.Int("mtu")
} else {
log.Fatalf("The MTU value passed [ %d ] must be greater than [ %d ] bytes per rfc791", ctx.Int("mtu"), minMTU)
return errors.New("the mtu must be int")
}
return nil
}
示例15: cmdRackScale
func cmdRackScale(c *cli.Context) {
count := 0
typ := ""
if c.IsSet("count") {
count = c.Int("count")
}
if c.IsSet("type") {
typ = c.String("type")
}
system, err := rackClient(c).ScaleSystem(count, typ)
if err != nil {
stdcli.Error(err)
return
}
fmt.Printf("Name %s\n", system.Name)
fmt.Printf("Status %s\n", system.Status)
fmt.Printf("Version %s\n", system.Version)
fmt.Printf("Count %d\n", system.Count)
fmt.Printf("Type %s\n", system.Type)
}