本文整理汇总了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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}