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

numbers as varying radix values, 15 0xF 0o17 1111 #4564

Open
epage opened this issue Dec 20, 2022 Discussed in #4563 · 1 comment
Open

numbers as varying radix values, 15 0xF 0o17 1111 #4564

epage opened this issue Dec 20, 2022 Discussed in #4563 · 1 comment
Labels
A-builder Area: Builder API C-enhancement Category: Raise on the bar on expectations S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing

Comments

@epage
Copy link
Member

epage commented Dec 20, 2022

Discussed in #4563

Originally posted by jtmoon79 December 19, 2022
tl;dr a nice feature for numbers would allow reading passed argument as differing radix among the traditional hexadecimal, decimal, octal, and binary.

I have implemented this here. It's a good bit of work. Would be nice if clap handled this for me. I'm imagining an option like allow_radix_all

    #[clap(
        required = false,
        long,
        default_value_t = 0xFFFF,
        allow_radix_all,
    )]
    number: u64,

And perhaps, further fine-grained options would also be allowed: allow_radix_hexadecimal, allow_radix_octal, allow_radix_binary. So allow_radix_all would just enable all the prior.
And might even want to throw in disallow_radix_decimal for some users that really want such.

Parsing could require a prepended 0 before the radix symbol, e.g. 0xF, 0d15, 0o17, 0b1111 and reject without, e.g. xF, d15, o17, b1111. or could be flexible and accept both. I'm not sure what is best there.

@epage epage added C-enhancement Category: Raise on the bar on expectations A-derive Area: #[derive]` macro API S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing A-builder Area: Builder API and removed A-derive Area: #[derive]` macro API labels Dec 20, 2022
@epage
Copy link
Member Author

epage commented Dec 20, 2022

There are a couple routes we can go with this

I somewhat lean towards supporting 0x, 0o, and 0b prefixes on integer value parsers without any configuration but am still undecided. One concern with this is the slipper slope for digit separators, "human sizes", etc which I wouldn't want to bake all of that in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-builder Area: Builder API C-enhancement Category: Raise on the bar on expectations S-waiting-on-design Status: Waiting on user-facing design to be resolved before implementing
Projects
None yet
Development

No branches or pull requests

1 participant