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


Golang Context.NArg方法代码示例

本文整理汇总了Golang中github.com/urfave/cli.Context.NArg方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.NArg方法的具体用法?Golang Context.NArg怎么用?Golang Context.NArg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/urfave/cli.Context的用法示例。


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

示例1: walletHistoryAction

func walletHistoryAction(c *gcli.Context) error {
	if c.NArg() > 0 {
		fmt.Printf("Error: invalid argument\n\n")
		gcli.ShowSubcommandHelp(c)
		return nil
	}
	f := c.String("f")
	if f == "" {
		f = filepath.Join(cfg.WalletDir, cfg.DefaultWalletName)
	}

	// check the file extension.
	if !strings.HasSuffix(f, walletExt) {
		return errWalletName
	}

	// check if file name contains path.
	if filepath.Base(f) != f {
		af, err := filepath.Abs(f)
		if err != nil {
			return fmt.Errorf("invalid wallet file:%v, err:%v", f, err)
		}
		f = af
	} else {
		f = filepath.Join(cfg.WalletDir, f)
	}

	// get all addresses in the wallet.
	addrs, err := getAddresses(f)
	if err != nil {
		return err
	}

	// get all the addresses affected uxouts
	uxouts, err := getAddrUxOuts(addrs)
	if err != nil {
		return err
	}

	// transmute the uxout to addrHistory, and sort the items by time in ascend order.
	totalAddrHis := []addrHistory{}
	for _, ux := range uxouts {
		addrHis, err := makeAddrHisArray(ux)
		if err != nil {
			return err
		}
		totalAddrHis = append(totalAddrHis, addrHis...)
	}

	sort.Sort(byTime(totalAddrHis))

	// print the addr history
	v, err := json.MarshalIndent(totalAddrHis, "", "    ")
	if err != nil {
		return errJSONMarshal
	}
	fmt.Println(string(v))
	return nil
}
开发者ID:skycoin,项目名称:skycoin,代码行数:59,代码来源:wallet_history.go

示例2: getToAddress

func getToAddress(c *gcli.Context) (string, error) {
	if c.NArg() < 2 {
		return "", errors.New("invalid argument")
	}

	toAddr := c.Args().First()
	// validate address
	if _, err := cipher.DecodeBase58Address(toAddr); err != nil {
		return "", err
	}

	return toAddr, nil
}
开发者ID:skycoin,项目名称:skycoin,代码行数:13,代码来源:create_rawtx.go

示例3: basics

func basics(c *cli.Context) error {
	if c.NArg() == 0 {
		return errors.New("no resume specified")
	}

	location := c.Args().Get(c.NArg() - 1)
	resume, err := dresh.FetchResume(location)
	if err != nil {
		return err
	}

	fmt.Println(dresh.BoxWrap(resume.Basics.Header(), resume.Basics.Content()))
	return nil
}
开发者ID:james-relyea,项目名称:dresh,代码行数:14,代码来源:main.go

示例4: gatherAddrs

func gatherAddrs(c *gcli.Context) ([]string, error) {
	w := c.String("f")
	var a string
	if c.NArg() > 0 {
		a = c.Args().First()
		if _, err := cipher.DecodeBase58Address(a); err != nil {
			return []string{}, fmt.Errorf("invalid address: %v", a)
		}
	}

	addrs := []string{}
	if w == "" && a == "" {
		// use default wallet
		w = filepath.Join(cfg.WalletDir, cfg.DefaultWalletName)
	}

	if w != "" {
		if !strings.HasSuffix(w, walletExt) {
			return []string{}, fmt.Errorf("error wallet file name, must has %v extension", walletExt)
		}

		if filepath.Base(w) == w {
			w = filepath.Join(cfg.WalletDir, w)
		} else {
			var err error
			w, err = filepath.Abs(w)
			if err != nil {
				return []string{}, err
			}
		}

		wlt, err := wallet.Load(w)
		if err != nil {
			return []string{}, err
		}

		addresses := wlt.GetAddresses()
		for _, a := range addresses {
			addrs = append(addrs, a.String())
		}
	}

	if a != "" {
		addrs = append(addrs, a)
	}

	return addrs, nil
}
开发者ID:skycoin,项目名称:skycoin,代码行数:48,代码来源:check_balance.go

示例5: getAmount

func getAmount(c *gcli.Context) (uint64, error) {
	if c.NArg() < 2 {
		return 0, errors.New("invalid argument")
	}
	amount := c.Args().Get(1)
	amt, err := strconv.ParseFloat(amount, 64)
	if err != nil {
		return 0, errors.New("error amount")
	}

	v := uint64(amt * 1e6)
	if (v % 1e6) != 0 {
		return 0, errors.New("skycoin coins must be multiple of 1e6")
	}

	return v, nil
}
开发者ID:skycoin,项目名称:skycoin,代码行数:17,代码来源:create_rawtx.go

示例6: work

func work(c *cli.Context) error {
	if c.NArg() == 0 {
		return errors.New("no resume specified")
	}

	location := c.Args().Get(c.NArg() - 1)
	resume, err := dresh.FetchResume(location)
	if err != nil {
		return err
	}

	career := resume.Work

	last := c.Int("last")
	if last != 0 {
		date := time.Now().AddDate(-1*last, 0, 0)
		career = career.Since(date)
	}

	since := c.String("since")
	if since != "" {
		date, err := time.Parse(dresh.DateLayout, since)
		if err != nil {
			return err
		}
		career = career.Since(date)
	}

	with := c.String("with")
	if with != "" {
		skills := strings.Split(with, ",")
		career = career.WorkingWith(skills)
	}

	for _, work := range career {
		fmt.Println(dresh.BoxWrap(work.Header(), work.Content()))
	}

	return nil
}
开发者ID:james-relyea,项目名称:dresh,代码行数:40,代码来源:main.go


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