-
Notifications
You must be signed in to change notification settings - Fork 161
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 format flag in chain head command #5215
feat: add format flag in chain head command #5215
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.
@akaladarshi Thanks for the contribution! In general, looks good. I requested some minor changes.
Also
- Pease add sample test to:
https://github.com/akaladarshi/forest/blob/akaladarshi/add-format-flag/scripts/tests/calibnet_other_check.sh#L32-L34
Something along forest-cli chain head --tipsets 5 --format json | jq
to assert valid JSON is produced
- Please add an entry to the changelog
src/cli/subcommands/chain_cmd.rs
Outdated
#[arg(short, long, default_value = "text")] | ||
format: Format, |
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.
Let's not use the short -f
here. Typically, it denotes --force
or --file
.
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.
Removed.
src/cli/subcommands/chain_cmd.rs
Outdated
cids: Vec<String>, | ||
} | ||
|
||
async fn collect_tipsets(client: &rpc::Client, n: u64) -> anyhow::Result<Vec<TipsetInfo>> { |
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.
Let's have a doc for the function.
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.
Done.
src/cli/subcommands/chain_cmd.rs
Outdated
cids: Vec<String>, | ||
} | ||
|
||
async fn collect_tipsets(client: &rpc::Client, n: u64) -> anyhow::Result<Vec<TipsetInfo>> { |
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.
async fn collect_tipsets(client: &rpc::Client, n: u64) -> anyhow::Result<Vec<TipsetInfo>> { | |
async fn collect_n_tipsets(client: &rpc::Client, n: u64) -> anyhow::Result<Vec<TipsetInfo>> { |
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.
Done.
src/cli/subcommands/chain_cmd.rs
Outdated
ensure!(n > 0, "number of tipsets must be positive"); | ||
let current_epoch = ChainHead::call(client, ()).await?.epoch() as u64; | ||
|
||
let mut result = Vec::with_capacity(n as usize); |
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.
let mut result = Vec::with_capacity(n as usize); | |
let mut tipsets = Vec::with_capacity(n as usize); |
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.
Done.
src/cli/subcommands/chain_cmd.rs
Outdated
|
||
/// Print the first `n` tipsets from the head (inclusive). | ||
async fn print_chain_head(client: &rpc::Client, n: u64, format: Format) -> anyhow::Result<()> { | ||
let result = collect_tipsets(client, n).await?; |
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.
let result = collect_tipsets(client, n).await?; | |
let tipsets = collect_tipsets(client, n).await?; |
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.
Done.
src/cli/subcommands/chain_cmd.rs
Outdated
/// Collects `n` tipsets from the head (inclusive) and returns them as a list of | ||
/// `TipsetInfo` objects. |
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.
Let's have proper Rust doc linking.
/// Collects `n` tipsets from the head (inclusive) and returns them as a list of | |
/// `TipsetInfo` objects. | |
/// Collects `n` tipsets from the head (inclusive) and returns them as a list of | |
/// [`TipsetInfo`] objects. |
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.
Done.
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!
Summary of changes
Changes introduced in this pull request:
--format
or-f
flag to theforest-cli chain head
command--format
flag acceptsjson
ortext
value, by defaulttext
Reference issue to close (if applicable)
#4954
Other information and links
Change checklist