-
Notifications
You must be signed in to change notification settings - Fork 80
feat(pretty-format): add pretty flag to format outputs in a tabular form #212
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
Conversation
Pull Request Test Coverage Report for Build 17246288729Details
💛 - Coveralls |
2ba0b94
to
3a5204f
Compare
efeb5ae
to
b1a05a6
Compare
I manually tested and everything works fine, my only small nit is that the Something like this in pub(crate) fn shorten(displayable: impl Display, start: u8, end: u8) -> String {
let displayable = displayable.to_string();
let start_str: &str = &displayable[0..start as usize];
let end_str: &str = &displayable[displayable.len() - end as usize..];
format!("{start_str}...{end_str}")
} Then the "outputs" match arm would look like: Unspent => {
let utxos = wallet.list_unspent().collect::<Vec<_>>();
if cli_opts.pretty {
let mut rows: Vec<Vec<CellStruct>> = vec![];
for utxo in &utxos {
let height = utxo
.chain_position
.confirmation_height_upper_bound()
.map(|h| h.to_string())
.unwrap_or("Pending".to_string());
let block_hash = match &utxo.chain_position {
ChainPosition::Confirmed { anchor, .. } => anchor.block_id.hash.to_string(),
ChainPosition::Unconfirmed { .. } => "Unconfirmed".to_string(),
};
rows.push(vec![
shorten(utxo.outpoint, 8, 10).cell(),
utxo.txout
.value
.to_sat()
.to_string()
.cell()
.justify(Justify::Right),
Address::from_script(&utxo.txout.script_pubkey, cli_opts.network).unwrap().cell(),
utxo.keychain.cell(),
utxo.is_spent.cell(),
utxo.derivation_index.cell(),
height.to_string().cell().justify(Justify::Right),
shorten(block_hash,8,8).cell().justify(Justify::Right),
]);
}
let table = rows
.table()
.title(vec![
"Outpoint".cell().bold(true),
"Output (sat)".cell().bold(true),
"Output Address".cell().bold(true),
"Keychain".cell().bold(true),
"Is Spent".cell().bold(true),
"Index".cell().bold(true),
"Block Height".cell().bold(true),
"Block Hash".cell().bold(true),
])
.display()
.map_err(|e| Error::Generic(e.to_string()))?;
Ok(format!("{table}"))
} else {
Ok(serde_json::to_string_pretty(&utxos)?)
}
} |
Also looks like you'll need to add some feature gating to fix the |
b1a05a6
to
015d8c2
Compare
Updated. Thank you for the suggestion, it fits just great. |
- add cli-table and `--pretty` flag to format output of commands in a tabular form for: - offline wallet commands - repl - compile commands - keys commands
015d8c2
to
98826f9
Compare
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.
ACK 98826f9
- update README for `--pretty` flag - update CHANGELOG
98826f9
to
94012c6
Compare
Fixes #193
Description
This PR adds a top level flag
--pretty
to format output in a tabular form to enhance readability for users.Notes to the reviewers
Changelog notice
--pretty
top level flag for formatting commands output in a tabular formatChecklists
All Submissions:
cargo fmt
andcargo clippy
before committingNew Features:
CHANGELOG.md