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

Flags().Uin64P broken #1474

Open
3 tasks done
blacktop opened this issue Dec 6, 2022 · 5 comments
Open
3 tasks done

Flags().Uin64P broken #1474

blacktop opened this issue Dec 6, 2022 · 5 comments
Labels
kind/bug Something isn't working

Comments

@blacktop
Copy link

blacktop commented Dec 6, 2022

Preflight Checklist

  • I have searched the issue tracker for an issue that matches the one I want to file, without success.
  • I am not looking for support or already pursued the available support channels without success.
  • I have checked the troubleshooting guide for my problem, without success.

Viper Version

v1.14.0

Go Version

1.19

Config Source

Flags

Format

Other (specify below)

Repl.it link

https://go.dev/play/p/5BSqnDuUn7B

Code reproducing the issue

package main

import (
	"fmt"
	"math"
	"strconv"

	"github.com/spf13/pflag"
	"github.com/spf13/viper"
)

func main() {
	pflag.Uint64P("int64", "u", 1, "test uint64 (int64 max)")
	pflag.Uint64P("uint64", "U", 1, "test uint64 (int64 max + 1)")

	err := viper.BindPFlag("VInt64", pflag.Lookup("int64"))
	if err != nil {
		panic(fmt.Errorf("viper.BindPFlag(VInt64): %v", err))
	}
	err = viper.BindPFlag("VUint64", pflag.Lookup("uint64"))
	if err != nil {
		panic(fmt.Errorf("viper.BindPFlag(VUint64): %v", err))
	}

	err = pflag.CommandLine.Parse([]string{"--int64", strconv.FormatUint(math.MaxInt64, 10), "--uint64", strconv.FormatUint(math.MaxInt64+1, 10)})
	if err != nil {
		panic(fmt.Errorf("pflag.CommandLine.Parse: %v", err))
	}

	i64, err := pflag.CommandLine.GetUint64("int64")
	if err != nil {
		panic(fmt.Errorf("pflag.CommandLine.GetUint64(int64): %v", err))
	}
	u64, err := pflag.CommandLine.GetUint64("uint64")
	if err != nil {
		panic(fmt.Errorf("pflag.CommandLine.GetUint64(uint64): %v", err))
	}

	fmt.Printf("pflag:\n  int64: %x\n  uint64: %x\n", i64, u64)
	fmt.Printf("viper:\n  int64: %x\n  uint64: %x\n", viper.GetUint64("VInt64"), viper.GetUint64("VUint64"))
}

Expected Behavior

If I have a LARGE uint64 flag it should parse it with no issue

Actual Behavior

it returns 0

Steps To Reproduce

https://go.dev/play/p/5BSqnDuUn7B

Additional Information

spf13/cobra#1869
spf13/cobra#1869

PR that fixes the issue

spf13/cast#155

@blacktop blacktop added the kind/bug Something isn't working label Dec 6, 2022
@github-actions
Copy link

github-actions bot commented Dec 6, 2022

👋 Thanks for reporting!

A maintainer will take a look at your issue shortly. 👀

In the meantime: We are working on Viper v2 and we would love to hear your thoughts about what you like or don't like about Viper, so we can improve or fix those issues.

⏰ If you have a couple minutes, please take some time and share your thoughts: https://forms.gle/R6faU74qPRPAzchZ9

📣 If you've already given us your feedback, you can still help by spreading the news,
either by sharing the above link or telling people about this on Twitter:

https://twitter.com/sagikazarmark/status/1306904078967074816

Thank you! ❤️

@blacktop
Copy link
Author

blacktop commented Dec 6, 2022

CREDIT for the code/playground goes to @memreflect 🥇

@blacktop
Copy link
Author

ping 🔔

@blacktop
Copy link
Author

blacktop commented Feb 5, 2023

ping

@sagikazarmark
Copy link
Collaborator

I'll see if I can get the cast pr merged. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants