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

Unexpected value. i want set default value #1276

Closed
4 of 7 tasks
Delgus opened this issue May 21, 2021 · 2 comments · Fixed by #1539
Closed
4 of 7 tasks

Unexpected value. i want set default value #1276

Delgus opened this issue May 21, 2021 · 2 comments · Fixed by #1539
Assignees
Labels
area/v2 relates to / is being considered for v2 kind/documentation describes a documentation update status/claimed someone has claimed this issue status/triage maintainers still need to look into this
Milestone

Comments

@Delgus
Copy link

Delgus commented May 21, 2021

my urfave/cli version is

( v.2.3.0)

Checklist

  • Are you running the latest v2 release? The list of releases is here.
  • Did you check the manual for your release? The v2 manual is here
  • Did you perform a search about this problem? Here's the Github guide about searching.

Dependency Management

  • My project is using go modules.
  • My project is using vendoring.
  • My project is automatically downloading the latest version.
  • I am unsure of what my dependency management setup is.

Describe the bug

I'm not sure if this is a bug, but the behavior is unexpected.

To reproduce

  1. set variable. For examplle, gcount := 20

  2. use pointer for destination

&cli.IntFlag{
				Name:        "power",
				Usage:       "count for goroutines",
				Destination: &gcount,
				DefaultText: "20",
			},
  1. Println in Action
Action: func(context *cli.Context) error {
			log.Println(gcount)

			return nil
		},

example application - https://play.golang.org/p/aXyfZus7pWi

package main

import (
	"log"
	"os"
	
	"github.com/urfave/cli/v2"
)

func main() {
	gcount := 20
	app := &cli.App{
		Name:  "leviathan",
		Usage: "pentest util",
		UsageText: "leviathan [command options] address (ip or host)",
		Flags: []cli.Flag{
			&cli.IntFlag{
				Name:        "power",
				Usage:       "count for goroutines",
				Destination: &gcount,
				DefaultText: "20",
			},
		},
		Action: func(context *cli.Context) error {
		        log.Println(gcount)
		        return nil
		},
	}

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

}

Observed behavior

gcount=0

Expected behavior

gcount=20

PS

After reading the documentation, I realized that I had to do this

Flags: []cli.Flag{
			&cli.IntFlag{
				Name:        "power",
				Usage:       "count for goroutines",
				//Destination: &gcount,
				DefaultText: "20",
				Value: 20,
			},
		},
Action: func(context *cli.Context) error {
            gcount := context.Int("power")

But I still think that the behavior is unexpected in my case.

@Delgus Delgus added area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/triage maintainers still need to look into this labels May 21, 2021
@stale
Copy link

stale bot commented Aug 21, 2021

This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else.

@stale stale bot added the status/stale stale due to the age of it's last update label Aug 21, 2021
@meatballhat meatballhat removed the status/stale stale due to the age of it's last update label Apr 21, 2022
@meatballhat meatballhat changed the title v2 bug: unexpected value. i want set default value Unexpected value. i want set default value Apr 21, 2022
@dearchap
Copy link
Contributor

dearchap commented Sep 11, 2022

@Delgus When you set the destination you have to set its value as well. So for example

gcount := 0
Flags: []cli.Flag{
			&cli.IntFlag{
				Name:        "power",
				Usage:       "count for goroutines",
                                Value: 20,
				Destination: &gcount,
				DefaultText: "20",
				Value: 20,
			},
		},

We probably need to update the documentation to reflect this

@dearchap dearchap added kind/documentation describes a documentation update and removed kind/bug describes or fixes a bug labels Sep 11, 2022
@dearchap dearchap added the status/claimed someone has claimed this issue label Oct 18, 2022
@dearchap dearchap self-assigned this Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/v2 relates to / is being considered for v2 kind/documentation describes a documentation update status/claimed someone has claimed this issue status/triage maintainers still need to look into this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants