clickup_cli/commands/
shared.rs1use clap::Subcommand;
2use crate::client::ClickUpClient;
3use crate::commands::auth::resolve_token;
4use crate::commands::workspace::resolve_workspace;
5use crate::error::CliError;
6use crate::output::OutputConfig;
7use crate::Cli;
8
9#[derive(Subcommand)]
10pub enum SharedCommands {
11 List,
13}
14
15pub async fn execute(command: SharedCommands, cli: &Cli) -> Result<(), CliError> {
16 let token = resolve_token(cli)?;
17 let client = ClickUpClient::new(&token, cli.timeout)?;
18 let output = OutputConfig::from_cli(&cli.output, &cli.fields, cli.no_header, cli.quiet);
19
20 match command {
21 SharedCommands::List => {
22 let team_id = resolve_workspace(cli)?;
23 let resp = client
24 .get(&format!("/v2/team/{}/shared", team_id))
25 .await?;
26
27 if cli.output == "json" {
28 println!("{}", serde_json::to_string_pretty(&resp).unwrap());
29 return Ok(());
30 }
31
32 let shared = resp.get("shared").cloned().unwrap_or(resp);
33 let tasks = shared
34 .get("tasks")
35 .and_then(|v| v.as_array())
36 .map(|a| a.len())
37 .unwrap_or(0);
38 let lists = shared
39 .get("lists")
40 .and_then(|v| v.as_array())
41 .map(|a| a.len())
42 .unwrap_or(0);
43 let folders = shared
44 .get("folders")
45 .and_then(|v| v.as_array())
46 .map(|a| a.len())
47 .unwrap_or(0);
48
49 let summary = vec![serde_json::json!({
50 "tasks": tasks,
51 "lists": lists,
52 "folders": folders,
53 })];
54 output.print_items(&summary, &["tasks", "lists", "folders"], "tasks");
55 Ok(())
56 }
57 }
58}