MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / output_table

Method output_table

atomic-cli/src/commands/identity/list.rs:126–180  ·  view source on GitHub ↗

Output identities as a table.

(
        &self,
        identities: &[atomic_identity::Identity],
        default_id: Option<&atomic_identity::IdentityId>,
    )

Source from the content-addressed store, hash-verified

124impl List {
125 /// Output identities as a table.
126 fn output_table(
127 &self,
128 identities: &[atomic_identity::Identity],
129 default_id: Option<&atomic_identity::IdentityId>,
130 ) {
131 let mut table = Table::new();
132
133 let mut columns = vec![
134 Column::new("NAME").min_width(12),
135 Column::new("TYPE").min_width(8),
136 Column::new("USAGE").min_width(10),
137 Column::new("EMAIL").min_width(20),
138 Column::new("DEFAULT").align(Alignment::Center),
139 ];
140
141 if self.verbose {
142 columns.push(Column::new("ID").min_width(10));
143 columns.push(Column::new("PUBLIC KEY").min_width(20));
144 }
145
146 table.set_columns(columns);
147
148 for identity in identities {
149 let is_default = default_id.map(|d| d == &identity.id).unwrap_or(false);
150
151 let mut row = vec![
152 identity.name.clone(),
153 super::format_identity_type(&identity.identity_type).to_string(),
154 super::format_usage(&identity.usage),
155 identity.email.clone().unwrap_or_default(),
156 if is_default {
157 "*".to_string()
158 } else {
159 String::new()
160 },
161 ];
162
163 if self.verbose {
164 row.push(identity.id.short());
165 row.push(format!("{}...", &identity.public_key_base32()[..16]));
166 }
167
168 table.add_row(row);
169 }
170
171 println!("{}", table);
172
173 // Print summary
174 println!();
175 print_info(&format!(
176 "{} identit{} found",
177 identities.len(),
178 if identities.len() == 1 { "y" } else { "ies" }
179 ));
180 }
181
182 /// Output identities as JSON.
183 fn output_json(

Callers 1

runMethod · 0.80

Calls 6

print_infoFunction · 0.85
min_widthMethod · 0.80
set_columnsMethod · 0.80
add_rowMethod · 0.80
pushMethod · 0.45
shortMethod · 0.45

Tested by

no test coverage detected