當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。