Example #1
0
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")
}
Example #2
0
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))
}
Example #3
0
func before(c *cli.Context) error {
	nodeAddr := c.String("node-addr")
	client = cclient.NewClient(nodeAddr, REQUEST_TYPE)
	return nil
}
Example #4
0
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))
}
Example #5
0
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))
}
Example #6
0
func cliCall(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")
	toAddr, gasS, data := c.String("to"), c.String("gas"), c.String("data")
	tx, err := core.Call(nodeAddr, pubkey, addr, toAddr, amtS, nonceS, gasS, feeS, data)
	common.IfExit(err)
	logger.Debugf("%v\n", tx)
	unpackSignAndBroadcast(core.SignAndBroadcast(chainID, nodeAddr, signAddr, tx, sign, broadcast, wait))
}
Example #7
0
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))
}