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

Method run

atomic-cli/src/commands/view/new.rs:341–485  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

339
340impl Command for New {
341 fn run(&self) -> CliResult<()> {
342 // Route EVERY form through the daemon — from/empty/plain and the
343 // --parent draft-workspace composition (the request's Parent arm).
344 if crate::commands::rpc::view_create(self)? {
345 return Ok(());
346 }
347
348 // Get the view name
349 let name = self
350 .name
351 .as_ref()
352 .ok_or_else(|| CliError::InvalidArgument {
353 message: "View name is required".to_string(),
354 })?;
355
356 // Validate the view name
357 validate_view_name(name).map_err(|msg| CliError::InvalidArgument { message: msg })?;
358
359 // Find the repository
360 let repo_root = find_repository_root()?;
361 let mut repo =
362 Repository::open_for_workspace_transaction(&repo_root).map_err(|e| match e {
363 atomic_repository::RepositoryError::NotFound { path } => {
364 CliError::RepositoryNotFound {
365 searched_path: path.into(),
366 }
367 }
368 other => CliError::Repository(other),
369 })?;
370
371 let workspace = enter_workspace(&mut repo, WorkspaceTxnMode::Reconcile)?;
372 let working_copy = workspace.working_copy();
373 let workspace_view = workspace.view().name.clone();
374
375 // Check if the view already exists
376 if repo.view_exists(name).map_err(CliError::Repository)? {
377 return Err(CliError::ViewAlreadyExists {
378 name: name.to_string(),
379 });
380 }
381
382 // If --from is specified, use dev's seeded-overlay path: the new
383 // view's filter starts with the source's change-set membership,
384 // anchored on --parent (or the source). The two-tier path below
385 // handles plain --draft/--parent creation.
386 if let Some(source) = self.from.clone() {
387 if !repo.view_exists(&source).map_err(CliError::Repository)? {
388 return Err(CliError::ViewNotFound { name: source });
389 }
390 let (anchor, seed) =
391 resolve_overlay_creation(self.from.as_deref(), self.parent.as_deref());
392 let source_info = seed
393 .as_deref()
394 .map(|seed_view| repo.get_view_info(seed_view))
395 .transpose()
396 .map_err(CliError::Repository)?;
397 repo.create_overlay_view(name, anchor.as_deref(), seed.as_deref())
398 .map_err(CliError::Repository)?;

Calls 15

view_createFunction · 0.85
find_repository_rootFunction · 0.85
RepositoryClass · 0.85
resolve_overlay_creationFunction · 0.85
print_successFunction · 0.85
as_refMethod · 0.80
view_existsMethod · 0.80
get_view_infoMethod · 0.80
create_overlay_viewMethod · 0.80
validate_view_nameFunction · 0.70
enter_workspaceFunction · 0.50