sharepoint_cli/commands/
config.rs1use crate::cli::{ConfigCmd, Runtime};
4use crate::error::Result;
5
6pub async fn run(rt: &Runtime, cmd: ConfigCmd) -> Result<()> {
7 match cmd {
8 ConfigCmd::Show => show(rt).await,
9 ConfigCmd::Path => path_only(rt).await,
10 }
11}
12
13async fn show(rt: &Runtime) -> Result<()> {
14 let value = serde_json::json!({
15 "profile": rt.cfg.profile_name,
16 "tenant_id": rt.cfg.tenant_id,
17 "client_id": rt.cfg.client_id,
18 "default_site": rt.cfg.default_site,
19 "read_only": rt.cfg.read_only,
20 "site_aliases": rt.cfg.site_aliases,
21 "graph_endpoint": rt.cfg.graph_endpoint,
22 "login_endpoint": rt.cfg.login_endpoint,
23 "config_path": rt.config_path.display().to_string(),
24 "cache_path": rt.cache_path.display().to_string(),
25 });
27 if rt.out.json {
28 rt.out.print_json(&value);
29 } else {
30 let masked = |key: &str| {
31 value
32 .get(key)
33 .and_then(serde_json::Value::as_str)
34 .unwrap_or("-")
35 };
36 rt.out.print_data(&format!(
37 "Profile: {}\nTenant: {}\nClient ID: {}\nDefault site: {}\nRead only: {}\nConfig: {}\nToken cache: {}",
38 masked("profile"),
39 masked("tenant_id"),
40 masked("client_id"),
41 masked("default_site"),
42 value["read_only"],
43 masked("config_path"),
44 masked("cache_path")
45 ));
46 }
47 Ok(())
48}
49
50async fn path_only(rt: &Runtime) -> Result<()> {
51 rt.out.print_data(&rt.config_path.display().to_string());
52 Ok(())
53}