当前位置: 首页>>代码示例>>Golang>>正文


Golang cli.Context类代码示例

本文整理汇总了Golang中github.com/eris-ltd/mint-client/Godeps/_workspace/src/github.com/codegangsta/cli.Context的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Context类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: cliBlocks

func cliBlocks(c *cli.Context) {
	args := c.Args()
	if len(args) == 0 {
		exit(fmt.Errorf("must specify a height to get a single block, or two heights to get all blocks between them"))
	} else if len(args) == 1 {
		height := args[0]
		i, err := strconv.ParseUint(height, 10, 32)
		ifExit(err)
		r, err := client.GetBlock(int(i))
		ifExit(err)
		s, err := formatOutput(c, 1, r)
		ifExit(err)
		fmt.Println(s)
	} else {
		minHeightS, maxHeightS := args[0], args[1]
		minHeight, err := strconv.ParseUint(minHeightS, 10, 32)
		ifExit(err)
		maxHeight, err := strconv.ParseUint(maxHeightS, 10, 32)
		ifExit(err)
		if maxHeight <= minHeight {
			exit(fmt.Errorf("maxHeight must be greater than minHeight"))
		}
		r, err := client.BlockchainInfo(int(minHeight), int(maxHeight))
		ifExit(err)
		s, err := formatOutput(c, 2, r)
		ifExit(err)
		fmt.Println(s)
	}
}
开发者ID:alist,项目名称:mint-client,代码行数:29,代码来源:cli.go

示例2: TestApp_RunAsSubcommandParseFlags

func TestApp_RunAsSubcommandParseFlags(t *testing.T) {
	var context *cli.Context

	a := cli.NewApp()
	a.Commands = []cli.Command{
		{
			Name: "foo",
			Action: func(c *cli.Context) {
				context = c
			},
			Flags: []cli.Flag{
				cli.StringFlag{
					Name:  "lang",
					Value: "english",
					Usage: "language for the greeting",
				},
			},
			Before: func(_ *cli.Context) error { return nil },
		},
	}
	a.Run([]string{"", "foo", "--lang", "spanish", "abcd"})

	expect(t, context.Args().Get(0), "abcd")
	expect(t, context.String("lang"), "spanish")
}
开发者ID:alist,项目名称:mint-client,代码行数:25,代码来源:app_test.go

示例3: cliStorage

func cliStorage(c *cli.Context) {
	args := c.Args()
	if len(args) == 0 {
		exit(fmt.Errorf("must specify an address to dump all storage, and an optional key to get just that storage"))
	} else if len(args) == 1 {
		addr := args[0]
		addrBytes, err := hex.DecodeString(addr)
		ifExit(err)
		r, err := client.DumpStorage(addrBytes)
		ifExit(err)
		s, err := formatOutput(c, 1, r)
		ifExit(err)
		fmt.Println(s)
	} else {
		addr, key := args[0], args[1]
		addrBytes, err := hex.DecodeString(addr)
		ifExit(err)
		keyBytes, err := hex.DecodeString(key)
		ifExit(err)
		r, err := client.GetStorage(addrBytes, keyBytes)
		ifExit(err)
		s, err := formatOutput(c, 2, r)
		ifExit(err)
		fmt.Println(s)
	}
}
开发者ID:alist,项目名称:mint-client,代码行数:26,代码来源:cli.go

示例4: cliAccounts

func cliAccounts(c *cli.Context) {
	args := c.Args()
	if len(args) == 0 {
		r, err := client.ListAccounts()
		ifExit(err)
		s, err := formatOutput(c, 0, r)
		ifExit(err)
		fmt.Println(s)
	} else {
		addr := args[0]
		addrBytes, err := hex.DecodeString(addr)
		if err != nil {
			exit(fmt.Errorf("Addr %s is improper hex: %v", addr, err))
		}
		r, err := client.GetAccount(addrBytes)
		ifExit(err)
		if r == nil {
			exit(fmt.Errorf("Account %X does not exist", addrBytes))
		}
		r2 := r.Account
		if r2 == nil {
			exit(fmt.Errorf("Account %X does not exist", addrBytes))
		}
		s, err := formatOutput(c, 1, r2)
		ifExit(err)
		fmt.Println(s)
	}
}
开发者ID:alist,项目名称:mint-client,代码行数:28,代码来源:cli.go

示例5: before

func before(c *cli.Context) error {
	var level int
	if c.GlobalBool("debug") || c.Bool("debug") {
		level = 2
	}
	log.SetLoggers(level, os.Stdout, os.Stderr)
	return nil
}
开发者ID:alist,项目名称:mint-client,代码行数:8,代码来源:main.go

示例6: formatOutput

func formatOutput(c *cli.Context, i int, o interface{}) (string, error) {
	args := c.Args()
	if len(args) < i+1 {
		return prettyPrint(o)
	}
	arg0 := args[i]
	v := reflect.ValueOf(o).Elem()
	name, err := FieldFromTag(v, arg0)
	if err != nil {
		return "", err
	}
	f := v.FieldByName(name)
	return prettyPrint(f.Interface())
}
开发者ID:alist,项目名称:mint-client,代码行数:14,代码来源:cli.go

示例7: cliCallCode

func cliCallCode(c *cli.Context) {
	args := c.Args()
	if len(args) < 3 {
		exit(fmt.Errorf("must specify code to execute and data to send"))
	}
	from, code, data := args[0], args[1], args[2]
	fromAddrBytes, err := hex.DecodeString(from)
	ifExit(err)
	codeBytes, err := hex.DecodeString(code)
	ifExit(err)
	dataBytes, err := hex.DecodeString(data)
	ifExit(err)
	r, err := client.CallCode(fromAddrBytes, codeBytes, dataBytes)
	ifExit(err)
	s, err := formatOutput(c, 3, r)
	ifExit(err)
	fmt.Println(s)
}
开发者ID:alist,项目名称:mint-client,代码行数:18,代码来源:cli.go

示例8: cliCall

func cliCall(c *cli.Context) {
	args := c.Args()
	if len(args) < 3 {
		exit(fmt.Errorf("must specify a from address, to address and data to send"))
	}
	from, to, data := args[0], args[1], args[2]
	fromAddrBytes, err := hex.DecodeString(from)
	ifExit(err)
	toAddrBytes, err := hex.DecodeString(to)
	ifExit(err)
	dataBytes, err := hex.DecodeString(data)
	ifExit(err)
	r, err := client.Call(fromAddrBytes, toAddrBytes, dataBytes)
	ifExit(err)
	s, err := formatOutput(c, 3, r)
	ifExit(err)
	fmt.Println(s)
}
开发者ID:alist,项目名称:mint-client,代码行数:18,代码来源:cli.go

示例9: cliBroadcast

func cliBroadcast(c *cli.Context) {
	args := c.Args()
	if len(args) < 1 {
		exit(fmt.Errorf("must specify transaction bytes to broadcast"))
	}
	txS := args[0]
	// TODO: we should switch over a hex vs. json flag
	txBytes, err := hex.DecodeString(txS)
	ifExit(err)
	var tx types.Tx
	n := new(int64)
	buf := bytes.NewBuffer(txBytes)
	wire.ReadBinary(tx, buf, n, &err)
	ifExit(err)
	r, err := client.BroadcastTx(tx)
	ifExit(err)
	r2 := r.Receipt
	s, err := formatOutput(c, 1, r2)
	ifExit(err)
	fmt.Println(s)
}
开发者ID:alist,项目名称:mint-client,代码行数:21,代码来源:cli.go

示例10: cliNames

func cliNames(c *cli.Context) {
	args := c.Args()
	if len(args) == 0 {
		r, err := client.ListNames()
		ifExit(err)
		s, err := formatOutput(c, 1, r)
		ifExit(err)
		fmt.Println(s)
	} else {
		name := args[0]
		r, err := client.GetName(name)
		ifExit(err)
		r2 := r.Entry
		s, err := formatOutput(c, 1, r2)
		ifExit(err)
		if len(args) > 1 {
			if args[1] == "data" {
				s, err = strconv.Unquote(s)
				ifExit(err)
			}
		}
		fmt.Println(s)
	}
}
开发者ID:alist,项目名称:mint-client,代码行数:24,代码来源:cli.go

示例11: cliBond

func cliBond(c *cli.Context) {
	chainID, nodeAddr, signAddr := c.String("chainID"), c.String("node-addr"), c.String("sign-addr")
	sign, broadcast, wait := c.Bool("sign"), c.Bool("broadcast"), c.Bool("wait")
	pubkey, amtS, nonceS, unbondAddr := c.String("pubkey"), c.String("amt"), c.String("nonce"), c.String("unbond-to")
	tx, err := core.Bond(nodeAddr, pubkey, unbondAddr, amtS, nonceS)
	common.IfExit(err)

	logger.Debugf("%v\n", tx)
	unpackSignAndBroadcast(core.SignAndBroadcast(chainID, nodeAddr, signAddr, tx, sign, broadcast, wait))
}
开发者ID:alist,项目名称:mint-client,代码行数:10,代码来源:cli.go

示例12: cliPermissions

func cliPermissions(c *cli.Context) {
	chainID, nodeAddr, signAddr := c.String("chainID"), c.String("node-addr"), c.String("sign-addr")
	sign, broadcast, wait := c.Bool("sign"), c.Bool("broadcast"), c.Bool("wait")
	pubkey, nonceS, addr := c.String("pubkey"), c.String("nonce"), c.String("addr")

	// all functions take at least 2 args (+ name)
	if len(c.Args()) < 3 {
		common.Exit(fmt.Errorf("Please enter the permission function you'd like to call, followed by it's arguments"))
	}
	permFunc := c.Args()[0]
	tx, err := core.Permissions(nodeAddr, pubkey, addr, nonceS, permFunc, c.Args()[1:])
	common.IfExit(err)
	logger.Debugf("%v\n", tx)
	unpackSignAndBroadcast(core.SignAndBroadcast(chainID, nodeAddr, signAddr, tx, sign, broadcast, wait))
}
开发者ID:alist,项目名称:mint-client,代码行数:15,代码来源:cli.go

示例13: cliName

func cliName(c *cli.Context) {
	chainID, nodeAddr, signAddr := c.String("chainID"), c.String("node-addr"), c.String("sign-addr")
	sign, broadcast, wait := c.Bool("sign"), c.Bool("broadcast"), c.Bool("wait")
	pubkey, amtS, nonceS, feeS, addr := c.String("pubkey"), c.String("amt"), c.String("nonce"), c.String("fee"), c.String("addr")

	if c.IsSet("data") && c.IsSet("data-file") {
		common.Exit(fmt.Errorf("Please specify only one of --data and --data-file"))
	}
	name, data, dataFile := c.String("name"), c.String("data"), c.String("data-file")
	if data == "" && dataFile != "" {
		b, err := ioutil.ReadFile(dataFile)
		common.IfExit(err)
		data = string(b)
	}
	tx, err := core.Name(nodeAddr, pubkey, addr, amtS, nonceS, feeS, name, data)
	common.IfExit(err)
	logger.Debugf("%v\n", tx)
	unpackSignAndBroadcast(core.SignAndBroadcast(chainID, nodeAddr, signAddr, tx, sign, broadcast, wait))
}
开发者ID:alist,项目名称:mint-client,代码行数:19,代码来源:cli.go

示例14: cliRebond

func cliRebond(c *cli.Context) {
	chainID, nodeAddr, signAddr := c.String("chainID"), c.String("node-addr"), c.String("sign-addr")
	sign, broadcast, wait := c.Bool("sign"), c.Bool("broadcast"), c.Bool("wait")
	addr, height := c.String("addr"), c.String("height")
	tx, err := core.Rebond(addr, height)
	common.IfExit(err)
	logger.Debugf("%v\n", tx)
	unpackSignAndBroadcast(core.SignAndBroadcast(chainID, nodeAddr, signAddr, tx, sign, broadcast, wait))
}
开发者ID:alist,项目名称:mint-client,代码行数:9,代码来源:cli.go


注:本文中的github.com/eris-ltd/mint-client/Godeps/_workspace/src/github.com/codegangsta/cli.Context类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。