Skip to content

Commit

Permalink
moss/cli/list: Fix emission to match column display
Browse files Browse the repository at this point in the history
Signed-off-by: Ikey Doherty <ikey@serpentos.com>
  • Loading branch information
ikeycode committed Oct 14, 2023
1 parent 8e69dde commit a9dfe29
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions moss/src/cli/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ pub async fn handle(args: &ArgMatches) -> Result<(), Error> {
.into_iter()
.map(|p| State {
name: p.meta.name.to_string(),
version: format!("{}-{}", p.meta.version_identifier, p.meta.source_release),
version: p.meta.version_identifier,
release: p.meta.source_release.to_string(),
summary: p.meta.summary,
})
.collect_vec();
Expand All @@ -65,18 +66,19 @@ pub async fn handle(args: &ArgMatches) -> Result<(), Error> {
// Grab maximum field
let max_element = set
.iter()
.max_by_key(|p| p.name.len() + p.version.len())
.max_by_key(|p| p.name.len() + p.release.len() + p.version.len())
.unwrap();
let max_length = max_element.name.len() + max_element.version.len();
let max_length = max_element.name.len() + max_element.version.len() + max_element.version.len();

// render
for st in set {
let width = (max_length - (st.name.len() + st.version.len())) + 2;
let width = (max_length - (st.name.len() + st.release.len() + st.version.len())) + 2;
println!(
"{} {:width$} {} - {}",
"{} {:width$} {}-{} - {}",
st.name.bold(),
" ",
st.version.magenta(),
st.release.dim(),
st.summary,
width = width
);
Expand All @@ -90,6 +92,7 @@ struct State {
name: String,
version: String,
summary: String,
release: String,
}

#[derive(Debug, Error)]
Expand Down

0 comments on commit a9dfe29

Please sign in to comment.