-
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
fix(cast storage): respect --json
for layout
#9332
fix(cast storage): respect --json
for layout
#9332
Conversation
Prior to this change, `cast storage $ADDRESS --rpc-url $RPC_URL --etherscan-api-key $ETHERSCAN_API_KEY` always provided a prettified output. This change adds a `--pretty` flag to `cast storage` which defaults to `true` thus retaining backwards compatibility. Passing `--pretty=false` to `cast storage` results in the json output of the storage layout being produced instead.
The default value is accessible via `cast storage --help`
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! left some comments, please also add a test similar with
foundry/crates/cast/tests/cli/main.rs
Line 1116 in a79dfae
casttest!(storage_layout_simple, |_prj, cmd| { |
@grandizzy Thanks for your review. Updated with your suggestions. |
--json
for layout
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, but checking the test you just added there's only the layout printed because of the early return on json format (and missing some important fields as the storage values), I guess we want to include them as well, or only the layout?
I added a |
…I key you already expect to fetch remote, very likely default)
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.
Implementation LGTM, made some minor modifications in regards to test as defaulting to quiet if shell is in JSON mode
Pending other reviewers cc @grandizzy
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.
Makes sense!
Thanks @MaxMustermann2! Merged |
Thank you both @grandizzy and @zerosnacks for your feedback and the commit. This will help with a Github workflow that I am working on; much appreciated. |
Motivation
Prior to this change,
cast storage $ADDRESS --rpc-url $RPC_URL --etherscan-api-key $ETHERSCAN_API_KEY
always provided a prettified output, ignoring the--json
flag.Solution
This change makes
cast storage
respect the--json
flag. If--slot
is omitted and this flag is provided, the storage layout JSON is printed to stdout, instead of the pretty layout. The values are printed as a separate list within the JSON.Example
This example is included as a test named
storage_layout_simple_json
.stdout.txt
stderr.txt