-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
feat(cast
): add flag equivalents of parseUnits, formatUnits
#9165
feat(cast
): add flag equivalents of parseUnits, formatUnits
#9165
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you! could you please add tests for these new options, you can see examples of usint casttest!
macro here https://github.com/foundry-rs/foundry/blob/master/crates/cast/tests/cli/main.rs
Also mind that "fu"
alias is already used for from-utf8
cast fu --help
Convert UTF8 text to hex
Usage: cast from-utf8 [TEXT]
hence tests are failing (see https://github.com/foundry-rs/foundry/blob/master/CONTRIBUTING.md#resolving-an-issue on how to run them locally)
thank you for reviewing @grandizzy. im not at home currently, will update tonight |
Hello @grandizzy , i updated the allias for formatUnits, added the tests and checked lint and testing on local |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, thanks! added comments re minor nits
@grandizzy tks. Updated |
oops, sorry, my suggestion to rename test broke it :) will revert |
@grandizzy no, i was my mistake, i change the function name incorrectly. Sry about that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thank you! @zerosnacks @yash-atreya mind review it too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @kien6034 for your PR, proposed feature LGTM
Tested it with a wide range of numbers and it works well
Noticed that it does not specifically handle hexadecimal numbers but that is OK as it is out of the scope of this ticket
…y-rs#9165) * feat: base func for parseunints and formatuints * test: update doc and tests * fix: function alias * test: cast test * refacctor: helper fucnction * Update crates/cast/tests/cli/main.rs * revert: format uints function cattest func name --------- Co-authored-by: grandizzy <[email protected]>
Motivation
Closes #9030
Solution
Add two new functions to support arbitrary decimal places in unit conversions:
parse_units
: Convert human-readable numbers to their smallest unit representationformat_units
: Convert numbers from smallest unit back to human-readable formatAdded test cases for common scenarios: