Skip to main content

clickup_cli/commands/
role.rs

1use 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 RoleCommands {
11    /// List custom roles in the workspace (Enterprise only)
12    List,
13}
14
15const ROLE_FIELDS: &[&str] = &["id", "name", "custom"];
16
17pub async fn execute(command: RoleCommands, cli: &Cli) -> Result<(), CliError> {
18    let token = resolve_token(cli)?;
19    let client = ClickUpClient::new(&token, cli.timeout)?;
20    let output = OutputConfig::from_cli(&cli.output, &cli.fields, cli.no_header, cli.quiet);
21
22    match command {
23        RoleCommands::List => {
24            let team_id = resolve_workspace(cli)?;
25            let resp = client
26                .get(&format!("/v2/team/{}/customroles", team_id))
27                .await?;
28            let roles = resp
29                .get("custom_roles")
30                .and_then(|r| r.as_array())
31                .cloned()
32                .unwrap_or_default();
33            output.print_items(&roles, ROLE_FIELDS, "id");
34            Ok(())
35        }
36    }
37}