wekan_cli/commands/profile/
use_profile.rs1use clap::Args;
2
3use crate::{
4 command_result::{CommandSuccess, ProfileItem},
5 config::profiles::{ProfileStore, parse_profile_name},
6 error::AppError,
7};
8
9use super::profile_not_found;
10
11#[derive(Debug, Args)]
12pub struct UseArgs {
13 #[arg(value_parser = parse_profile_name)]
14 pub name: String,
15}
16
17pub(super) fn execute(
18 args: UseArgs,
19 profile_store: &dyn ProfileStore,
20) -> Result<CommandSuccess, AppError> {
21 let mut mutation = profile_store.lock_mutation().map_err(AppError::from)?;
22 let profile = mutation
23 .document()
24 .profile(&args.name)
25 .ok_or_else(|| profile_not_found(&args.name))?;
26 let server = profile.server().to_owned();
27 if mutation.document().active_profile() != Some(args.name.as_str()) {
28 let mut document = mutation.document().clone();
29 document.set_active_profile(Some(args.name.clone()));
30 mutation.save(document)?;
31 }
32 Ok(CommandSuccess::ProfileUsed(ProfileItem {
33 name: args.name,
34 server,
35 active: true,
36 }))
37}