-
Notifications
You must be signed in to change notification settings - Fork 26
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: add option to output metadata to a file #61
feat: add option to output metadata to a file #61
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 for this PR @trusch, this is a great addition.
I would like to add this feature but I find the assymetry it introduces potentially confusing:
--json
outputs json (ie non scale) to stdout (former behavior)--output <file>
stores the scale encoded version to--json --output <file>
stores the scale encoded as json to file
I fear this last one will be confusing and people may not expect getting the scale encoded version from the last one.
How about:
--json
: for json output--scale
: for scale output, can be called with--json
as well--output <file>
takes care of writting to disk any of the options above:--json
--json --scale
--scale
- without
--output
, we use stdout
The benefit of not merging --scale
and --output
is that a user could also do something like scale_encoded=$(subwasm meta --scale --json)
which can be useful for CI and does not require saving into a file.
Currently (in this PR) But actually I like the idea of combining --json and --scale to produce something like Ok, let summarize:
If we agree on that I'll restructure the main to reflect that :) |
No this is not the current behavior, currently it outputs a human friendly list of pallets and the user can dig in using an extra
Not same as above, this one shows the raw json version
yep, that would be great, I guess you mean to stdout here
fine by me
We may drop
any "same than above" is likley not required
see above
can we not drop
If we have several "format" for |
I just discovered that there are even emojis in the human readable output when specifying a module, lfg! Ok, new UX proposal: We have a flag Does that sound better? |
Yes that sounds very good actually 👍 I indeed would like to keep I am not against some In theory, you may want to even do stuff like Having such a new Cherry on top, for the default file, we may want to keep track of what is the appropriate extension for a given format. For instance:
Those will be user overridable anyway to we help making it easy without getting in the way. |
@chevdor that took a little more effort than anticipated, but besides a few minor warnings (error handling in those macros is hard) it should now do exactly what we want. Only thing I don't know what to do is with the --json flag. Should we respect it for backward compability and translate it to "--format json"? |
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.
I want to test carefully but that looks very good already, I also appreciate the extra cleanup !
// The following fails if piped to another command that truncates the output. | ||
// Typical use case here is: subwasm meta | head | ||
// The failure is due to https://github.com/rust-lang/rust/issues/46016 | ||
// TODO: Once the above is fixed, we can remove the dependency on calm_io | ||
// println!("{}", serialized); |
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.
Did you test that part ?
I see the issue is still open.
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.
The root cause of this issue is that we can't ignore the broken pipe error in a println! call. Since all printing is now done through writeln macro calls I just improved error propagation and added a top-level check to ignore the broken pipe error. I consequently removed the calm_io dependency.
While doing so I saw you already started using color_eyre, so I properly installed it in the beginning of main and also replaced a lot of unwraps and panics with better error propagation.
You will be happy seeing the next error. That eyre crate is really nice, I didn't used it before.
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.
If you do RUST_LOG=subwasm=debug
you can see a debug line when the broken pipe error is ignored.
Yes, I do see the extra work, thanks a lot for that !
Yes I want to be extra cautious with that since parity and probably other users may be counting on that.
I think the first option is cleaner. |
@chevdor Broken Pipe errors are now ignored again + there is now a warning about the deprecation of --json when you use it in the context of retrieving metadata. Error handling is also much better now. Hope you like it now :) |
Nice work on that PR @trusch, thank you! |
tried to use output of subwasm as input to subxt. not worked. |
Can you please open a new issue and provide more details ? |
This adds a
--output
flag to the metadata subcommand. If specified, the prefixed scale-encoded metadata is written to the file as expected by for example subxt or the polkadotjs/api augmentation scripts. If the global--json
flag is set, the json of the prefixed metadata is written to the file.The normal json output is not changed to not break backward compability.
We need this because we want to expose the metadata of our chain directly from CI and don't want to spin up a local parachain setup just to query the metadata from a live node.
Ps: I really like this tool, getting the metadata directly from the wasm is super nice!
edit: Fixes #58