Conversation
Either Candid UI or |
| .await | ||
| .with_context(|| format!("Failed to read controllers of canister {}.", canister_id))?; | ||
|
|
||
| stdout().write_all(&metadata)?; |
There was a problem hiding this comment.
Not sure the best way to display this. Some of the metadata may not be printable ascii. Maybe we can check if metadata is printable, if not, we display the hex instead.
There was a problem hiding this comment.
Would it make sense to have an --outfile flag instead/in addition?
There was a problem hiding this comment.
@chenyan-dfinity @sesi200 I wondered about these too. Not sure of the best way either.
The thinking was that by writing the raw data bytes to stdout, they can be written to a file or piped to another program.
While the metadata may not be printable ascii, what if the developer wants to run the actual contents through hexdump or some other tool? If dfx canister metadata ... | hexdump -C, and the metadata is not entirely printable ascii, what would the expected behavior be?
What would the proposed rules be? Would they more clear than always writing as-is to stdout? The below seem overly complicated to me.
- if
--outfilespecified, write data to specified file as-is.--outfile -means write data as-is to stdout. - If no
--outfilespecified, and metadata is printable ascii, write that to stdout. - If no
--outfilespecified, and metadata is not all printable ascii, then write an explanation to stderr and display metadata as hex to stdout.
There was a problem hiding this comment.
I have no strong opinion either way and have no problem merging this as-is. I was mostly thinking about invoking dfx from somewhere that doesn't have such trivial redirect mechanics, but I might just be overthinking it.
My approach would have been to print to --outfile if specified, otherwise print to stdout. Reason being that I'd want to give a way to not see garbage printed if it is expected.
| use ic_types::Principal; | ||
| use std::io::{stdout, Write}; | ||
|
|
||
| /// Sign a canister call and generate message file. |
There was a problem hiding this comment.
| /// Sign a canister call and generate message file. | |
| /// Displays metadata in a canister. |
There was a problem hiding this comment.
I went ahead and merged this already
Description
Adds
dfx canister metadata <canister> <metadata name>command, for exampledfx canister metadata something_backend candid:serviceto display the candid service definition for the backend canister.Open questions:
/_/candidendpoint. That endpoint, however, has options for formatting the candid definition in either.jsor.tsformat. Should this command have some option to perform that transformation, or is there some other tool that is better suited to the purpose? What is an example of a consumer of that functionality?Fixes https://dfinity.atlassian.net/browse/SDK-346
How Has This Been Tested?
Added e2e tests
Checklist: