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

Method run

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

Source from the content-addressed store, hash-verified

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