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

Method run

atomic-cli/src/commands/view/list.rs:221–307  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

219
220impl Command for List {
221 fn run(&self) -> CliResult<()> {
222 // Remote listing takes over entirely when --remote is present.
223 if let Some(remote_arg) = &self.remote {
224 return self.run_remote(remote_arg);
225 }
226
227 // Find the repository
228 let repo_root = find_repository_root()?;
229 let repo = Repository::open(&repo_root).map_err(|e| match e {
230 atomic_repository::RepositoryError::NotFound { path } => CliError::RepositoryNotFound {
231 searched_path: path.into(),
232 },
233 other => CliError::Repository(other),
234 })?;
235
236 // Get list of views
237 let views = repo.list_views().map_err(CliError::Repository)?;
238 let current = repo.current_view();
239
240 if views.is_empty() {
241 println!(
242 "{}",
243 hint("No views found. Use 'atomic view create <name>' to create one.")
244 );
245 return Ok(());
246 }
247
248 // Sort views alphabetically, but keep current view considerations
249 let mut sorted_views = views;
250 sorted_views.sort();
251
252 // Calculate padding for alignment
253 let max_name_len = sorted_views.iter().map(|s| s.len()).max().unwrap_or(0);
254
255 for view in sorted_views {
256 let is_current = view == current;
257 let marker = if is_current { "*" } else { " " };
258
259 if self.short {
260 println!("{} {}", marker, style_view(&view));
261 } else {
262 match repo.get_view_info(&view) {
263 Ok(info) => {
264 let kind_tag = match info.kind_label() {
265 "draft" => "[draft]",
266 _ => "[shared]",
267 };
268 let parent_info = match &info.parent_name {
269 Some(p) => format!(" parent: {}", style_view(p)),
270 None => String::new(),
271 };
272 // Show own changes for views with a parent;
273 // show total for root views.
274 let change_display = if info.parent_name.is_some() {
275 let own = info.own_change_count;
276 let inherited = info.change_count.saturating_sub(info.own_change_count);
277 if own == 1 {
278 format!("({} change, {} inherited)", own, inherited)

Callers 5

test_list_default_viewFunction · 0.45
test_list_multiple_viewsFunction · 0.45
test_list_verboseFunction · 0.45
test_list_after_switchFunction · 0.45

Calls 11

find_repository_rootFunction · 0.85
RepositoryClass · 0.85
run_remoteMethod · 0.80
current_viewMethod · 0.80
sortMethod · 0.80
get_view_infoMethod · 0.80
kind_labelMethod · 0.80
list_viewsMethod · 0.45
is_emptyMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45

Tested by 5

test_list_default_viewFunction · 0.36
test_list_multiple_viewsFunction · 0.36
test_list_verboseFunction · 0.36
test_list_after_switchFunction · 0.36