`atomic view create` over CreateView — every form. `--from` seeds on the source view, `--parent` anchors on the parent WITHOUT seeding (the draft workspace form, the wire's Parent arm), `--empty`/plain anchor on the nearest Shared ancestor; `--switch` chains the SwitchView RPC.
(args: &super::view::New)
| 3543 | /// anchor on the nearest Shared ancestor; `--switch` chains the |
| 3544 | /// SwitchView RPC. |
| 3545 | pub fn view_create(args: &super::view::New) -> CliResult<bool> { |
| 3546 | let Some(name) = args.name.clone() else { |
| 3547 | return Err(CliError::InvalidArgument { |
| 3548 | message: "View name is required".to_string(), |
| 3549 | }); |
| 3550 | }; |
| 3551 | // The local body's name validation stays client-side — the same |
| 3552 | // messages, checked before any wire round-trip. |
| 3553 | super::view::new::validate_view_name(&name) |
| 3554 | .map_err(|message| CliError::InvalidArgument { message })?; |
| 3555 | let Some(session) = Service::open()? else { |
| 3556 | return Ok(false); |
| 3557 | }; |
| 3558 | let base = if let Some(from) = &args.from { |
| 3559 | Some(pb::create_view_request::Base::FromView(from.clone())) |
| 3560 | } else if let Some(parent) = &args.parent { |
| 3561 | // --parent: anchor on the parent WITHOUT seeding (draft workspace). |
| 3562 | Some(pb::create_view_request::Base::Parent(parent.clone())) |
| 3563 | } else if args.empty { |
| 3564 | Some(pb::create_view_request::Base::Empty(true)) |
| 3565 | } else { |
| 3566 | None |
| 3567 | }; |
| 3568 | let request = pb::CreateViewRequest { |
| 3569 | repository: Some(session.reference.clone()), |
| 3570 | meta: None, |
| 3571 | name: name.clone(), |
| 3572 | base, |
| 3573 | scope: pb::ViewScope::Unspecified as i32, |
| 3574 | base_snapshot: None, |
| 3575 | }; |
| 3576 | let response = session.create_view(request)?; |
| 3577 | let view = response.view.expect("created view info"); |
| 3578 | if args.switch { |
| 3579 | view_switch_plain(&session, &name)?; |
| 3580 | } else { |
| 3581 | print_hint(&format!( |
| 3582 | "Use 'atomic view switch {name}' to switch to the new view" |
| 3583 | )); |
| 3584 | } |
| 3585 | let seeded = view.change_count > 0; |
| 3586 | if seeded { |
| 3587 | print_success(&format!( |
| 3588 | "Created view: {name} (seeded - {} changes)", |
| 3589 | view.change_count |
| 3590 | )); |
| 3591 | } else { |
| 3592 | print_success(&format!("Created view: {name}")); |
| 3593 | } |
| 3594 | Ok(true) |
| 3595 | } |
| 3596 | |
| 3597 | /// `atomic view switch` over SwitchView — every form: --force/--stash |
| 3598 | /// ride the request's explicit dirty-copy bypass (the caller's informed |
no test coverage detected