Cli: cannot use cli.IntFlag literal (type cli.IntFlag) as type cli.Flag in array or slice literal: cli.IntFlag does not implement cli.Flag (Apply method has pointer receiver)

Created on 17 Jun 2016  Â·  13Comments  Â·  Source: urfave/cli

_Here is the fix for this issue! => https://github.com/urfave/cli/issues/459#issuecomment-555077623_

_edited by @lynncyrin!_


I updated today and can't build my app (luckily I do vendoring). Am I missing any API change? The error is below:

cannot use cli.IntFlag literal (type cli.IntFlag) as type cli.Flag in array or slice literal:
        cli.IntFlag does not implement cli.Flag (Apply method has pointer receiver)

Also, why the change from codegangsta/cli to urfave/cli? I couln't find any information on README or anywhere.

Cheers.

Most helpful comment

For everyone having the same problem... Just add a "&" at the beginning of the IntFlag or StringFlag (or whatever flag you have)... Yeah... Took me 1 hour to realise that... Example:

func flags() {
    flag1 := cli.IntFlag{
        Name:        "id",
        Usage:       "id for identification",
        Destination: &id,
    }
    flag2 := cli.StringFlag{
        Name:        "token",
        Usage:       "token verification",
        Destination: &token,
    }
    app.Flags = []cli.Flag {
        &flag1,
        &flag2,
    }
}

All 13 comments

Also getting it for other flag types as well (although it builds locally for me so it must be a recent change?)

cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in array element:
    cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver)
cannot use cli.StringSliceFlag literal (type cli.StringSliceFlag) as type cli.Flag in array element:
    cli.StringSliceFlag does not implement cli.Flag (Apply method has pointer receiver)

Are both of you pinning to the v2 branch?

On Fri, Jun 17, 2016, 18:44 Edward Paulet [email protected] wrote:

Also getting it for other flag types as well (although it builds locally
for me so it must be a recent change?)

cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in array element:
cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver)

cannot use cli.StringSliceFlag literal (type cli.StringSliceFlag) as type cli.Flag in array element:
cli.StringSliceFlag does not implement cli.Flag (Apply method has pointer receiver)

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/urfave/cli/issues/459#issuecomment-226898701, or mute
the thread
https://github.com/notifications/unsubscribe/AACwV3h6Ww1qpb-RkrIu4uXbLR6Dzbq5ks5qMyNmgaJpZM4I4jdz
.

Yes. I forgot to mention that in my original post.

Yes, v2

Ah cool. Sorry about the surprise. The v2 branch is volatile, and recently
received a patch to introduce a lot more pointer receivers. Switching from
struct literals to pointers to struct literals should do the trick. The
change log for v2 changes should cover everything, and please yell if it
doesn't. There is also a migration script in the repo root that may help.
Please provide feedback! :smile_cat:

On Fri, Jun 17, 2016, 18:53 Edward Paulet [email protected] wrote:

Yes. I forgot to mention that in my original post.

—
You are receiving this because you commented.

Reply to this email directly, view it on GitHub
https://github.com/urfave/cli/issues/459#issuecomment-226899812, or mute
the thread
https://github.com/notifications/unsubscribe/AACwVzijUF0F-U-a1UrhlxZ9bReN6Thvks5qMyVSgaJpZM4I4jdz
.

related: thoughts on renaming the v2 branch to v2pre or equiv?

My fault that I thought the v2 was stable. Downgrading to v1 fixed for me. Thank you.

@andreynering :+1:

Hi, I have the same problem but with version 1. I tried to copy the code snippets from the documentation but no luck... Any ideas what the problem could be?

For everyone having the same problem... Just add a "&" at the beginning of the IntFlag or StringFlag (or whatever flag you have)... Yeah... Took me 1 hour to realise that... Example:

func flags() {
    flag1 := cli.IntFlag{
        Name:        "id",
        Usage:       "id for identification",
        Destination: &id,
    }
    flag2 := cli.StringFlag{
        Name:        "token",
        Usage:       "token verification",
        Destination: &token,
    }
    app.Flags = []cli.Flag {
        &flag1,
        &flag2,
    }
}

On v1, just got bit by this right now. @Tengoru's example fixed it for me.

app.Flags = []cli.Flag{
    &cli.StringFlag{
      Name:  "config, c",
      Usage: "Load configuration from `FILE`",
    },
  }

Worked for me.

app.Flags = []cli.Flag{
&cli.StringFlag{
Name: "name, n",
Usage: "Print Hello World`",
},
}
works just fine

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cab picture cab  Â·  18Comments

lynncyrin picture lynncyrin  Â·  39Comments

slantview picture slantview  Â·  44Comments

Nokel81 picture Nokel81  Â·  17Comments

Nokel81 picture Nokel81  Â·  14Comments