Preflight Checklist

  • [X] I have searched the issue tracker for an issue that matches the one I want to file, without success.
  • [X] I am not looking for support or already pursued the available support channels without success.
  • [X] 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

https://github.com/spf13/cobra/issues/1869 https://github.com/spf13/cobra/issues/1869

PR that fixes the issue

https://github.com/spf13/cast/pull/155

Comment From: github-actions[bot]

👋 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! ❤️

Comment From: blacktop

CREDIT for the code/playground goes to @memreflect 🥇

Comment From: blacktop

ping 🔔

Comment From: blacktop

ping

Comment From: sagikazarmark

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

Comment From: github-actions[bot]

Issues with no activity for 30 days are marked stale and subject to being closed.