cloud_disk_sync/utils/
interaction.rs1use crate::config::AccountConfig;
2use crate::utils::account::find_account_id_internal;
3use crate::utils::path::parse_account_path;
4use std::collections::HashMap;
5
6pub async fn parse_account_path_or_select(
7 input: &str,
8 accounts: &HashMap<String, AccountConfig>,
9 account_list: &[(String, String)],
10 account_display: &[String],
11 label: &str,
12) -> Result<(String, String), Box<dyn std::error::Error>> {
13 if let Ok((acc, path)) = parse_account_path(input) {
15 let acc_id = find_account_id_internal(accounts, &acc);
17 if let Some(id) = acc_id {
18 return Ok((id, path));
19 } else {
20 }
23 }
24
25 let acc_id = find_account_id_internal(accounts, input);
27 if let Some(id) = acc_id {
28 let path = dialoguer::Input::<String>::new()
30 .with_prompt(format!("请输入{}路径", label))
31 .default("/".to_string())
32 .interact_text()?;
33 return Ok((id, path));
34 }
35
36 println!("⚠️ 无法解析账户: {}", input);
38 select_account_and_path(accounts, account_list, account_display, label).await
39}
40
41pub async fn select_account_and_path(
42 accounts: &HashMap<String, AccountConfig>,
43 account_list: &[(String, String)],
44 account_display: &[String],
45 label: &str,
46) -> Result<(String, String), Box<dyn std::error::Error>> {
47 use dialoguer::{Input, Select};
48
49 let selection = Select::new()
50 .with_prompt(format!("选择{}账户", label))
51 .items(account_display)
52 .default(0)
53 .interact()?;
54
55 let (account_id, _) = &account_list[selection];
56 let account = accounts.get(account_id).unwrap();
57
58 let path = match account.provider {
60 _ => Input::<String>::new()
63 .with_prompt(format!("请输入{}路径", label))
64 .default("/".to_string())
65 .interact_text()?,
66 };
67
68 Ok((account_id.clone(), path))
69}