Cli: Cannot use func literal

Created on 3 May 2016  路  2Comments  路  Source: urfave/cli

Expected

For the example provided to work

Actual

Does not work :(

Steps to re-produce

  1. Use go 1.6
  2. Copy example from README and run: go run main.go
package main

import (
  "os"

  "github.com/codegangsta/cli"
)

func main() {
  app := cli.NewApp()
  app.Flags = []cli.Flag{
    cli.BoolTFlag{
      Name:  "ginger-crouton",
      Usage: "is it in the soup?",
    },
  }
  app.Action = func(ctx *cli.Context) error {
    if !ctx.Bool("ginger-crouton") {
      return cli.NewExitError("it is not in the soup", 86)
    }
    return nil
  }

  app.Run(os.Args)
}

Errors:

$ go run main.go
# command-line-arguments
./main.go:19: undefined: cli.NewExitError
./main.go:22: cannot use func literal (type func(*cli.Context) error) as type func(*cli.Context) in assignment
kinbug

Most helpful comment

you got that right... damn go get -u fixed it.
Thanks

All 2 comments

@FrenchBen This looks to me like an (unexpectedly) older version of cli is being used by your go run command. Can you verify that you don't have any older versions available in your $GOPATH?

you got that right... damn go get -u fixed it.
Thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lynncyrin picture lynncyrin  路  39Comments

johnwyles picture johnwyles  路  17Comments

nikkolasg picture nikkolasg  路  16Comments

fgblomqvist picture fgblomqvist  路  21Comments

ansrivas picture ansrivas  路  17Comments