Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1 error :cannot use ([]cli.Command literal) #964

Closed
AchalaSB opened this issue Nov 29, 2019 · 2 comments
Closed

V1 error :cannot use ([]cli.Command literal) #964

AchalaSB opened this issue Nov 29, 2019 · 2 comments
Assignees
Labels
area/v1 relates to / is being considered for v1 kind/bug describes or fixes a bug status/triage maintainers still need to look into this

Comments

@AchalaSB
Copy link

my urfave/cli version is

version v1
Getting error in v1 version. The same code I ran 15days before it was working fine. but now its not working. I haven't changed the version.

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/urfave/cli"
)

func main() {
	app := cli.NewApp()

	app.Commands = []cli.Command{
		{
			Name:    "add",
			Aliases: []string{"a"},
			Usage:   "add a task to the list",
			Flags: []cli.Flag{
				cli.StringFlag{Name: "message, m"},
			},
			Action: func(c *cli.Context) error {
				fmt.Println("added task: ", c.Args().First())
				return nil
			},
		},
		{
			Name:    "complete",
			Aliases: []string{"c"},
			Usage:   "complete a task on the list",
			Action: func(c *cli.Context) error {
				fmt.Println("completed task: ", c.Args().First())
				return nil
			},
		},
	}

	err := app.Run(os.Args)
	if err != nil {
		log.Fatal(err)
	}
}

error log

cannot use ([]cli.Command literal) (value of type []cli.Command) as []*cli.Command value in assignment
cannot use (cli.StringFlag literal) (value of type cli.StringFlag) as cli.Flag value in array or slice literal: missing method Apply

Run go version and paste its output here

go version go1.13.4 linux/amd64

Run go env and paste its output here

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/achala/.cache/go-build"
GOENV="/home/achala/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/achala/go/"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build979489797=/tmp/go-build -gno-record-gcc-switches"

@AchalaSB AchalaSB added status/triage maintainers still need to look into this kind/bug describes or fixes a bug area/v1 relates to / is being considered for v1 labels Nov 29, 2019
@coilysiren
Copy link
Member

coilysiren commented Nov 29, 2019

@AchalaSB []cli.Command was changed to []*cli.Command in v2, please do either of the following things:

@abdennour
Copy link

For me i get similar error, but it's nothing to do with migration.

Simply, it's was a typo that the function does not return error in its signature:

// issue
func DetectPrintln(ctx *cli.Context) {

// OK
func DetectPrintln(ctx *cli.Context) error {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/v1 relates to / is being considered for v1 kind/bug describes or fixes a bug status/triage maintainers still need to look into this
Projects
None yet
Development

No branches or pull requests

3 participants