| 79 | |
| 80 | impl Command for List { |
| 81 | fn run(&self) -> CliResult<()> { |
| 82 | // Find the repository |
| 83 | let repo_root = find_repository_root()?; |
| 84 | let repo = Repository::open(&repo_root).map_err(|e| match e { |
| 85 | atomic_repository::RepositoryError::NotFound { path } => CliError::RepositoryNotFound { |
| 86 | searched_path: path.into(), |
| 87 | }, |
| 88 | other => CliError::Repository(other), |
| 89 | })?; |
| 90 | |
| 91 | // Get list of views |
| 92 | let views = repo.list_views().map_err(CliError::Repository)?; |
| 93 | let current = repo.current_view(); |
| 94 | |
| 95 | if views.is_empty() { |
| 96 | println!( |
| 97 | "{}", |
| 98 | hint("No views found. Use 'atomic view create <name>' to create one.") |
| 99 | ); |
| 100 | return Ok(()); |
| 101 | } |
| 102 | |
| 103 | // Sort views alphabetically, but keep current view considerations |
| 104 | let mut sorted_views = views; |
| 105 | sorted_views.sort(); |
| 106 | |
| 107 | // Calculate padding for alignment |
| 108 | let max_name_len = sorted_views.iter().map(|s| s.len()).max().unwrap_or(0); |
| 109 | |
| 110 | for view in sorted_views { |
| 111 | let is_current = view == current; |
| 112 | let marker = if is_current { "*" } else { " " }; |
| 113 | |
| 114 | if self.short { |
| 115 | println!("{} {}", marker, style_view(&view)); |
| 116 | } else { |
| 117 | match repo.get_view_info(&view) { |
| 118 | Ok(info) => { |
| 119 | let kind_tag = match info.kind_label() { |
| 120 | "draft" => "[draft]", |
| 121 | _ => "[shared]", |
| 122 | }; |
| 123 | let parent_info = match &info.parent_name { |
| 124 | Some(p) => format!(" parent: {}", style_view(p)), |
| 125 | None => String::new(), |
| 126 | }; |
| 127 | // Show own changes for views with a parent; |
| 128 | // show total for root views. |
| 129 | let change_display = if info.parent_name.is_some() { |
| 130 | let own = info.own_change_count; |
| 131 | let inherited = info.change_count.saturating_sub(info.own_change_count); |
| 132 | if own == 1 { |
| 133 | format!("({} change, {} inherited)", own, inherited) |
| 134 | } else { |
| 135 | format!("({} changes, {} inherited)", own, inherited) |
| 136 | } |
| 137 | } else if info.change_count == 1 { |
| 138 | format!("({} change)", info.change_count) |