use clap::{Args, Parser, Subcommand};
use clap_complete::Shell;
use crate::output::OutputFormat;
#[derive(Debug, Parser)]
#[command(
name = "teams",
version,
about = "Microsoft Teams from your terminal, for humans and agents",
after_help = "Get started:\n teams init Guided setup\n teams tui --demo Explore without an account\n teams doctor Diagnose configuration and access\n teams schema --command 'messages send'\n Inspect the automation contract"
)]
pub struct Cli {
#[arg(long, global = true, env = "TEAMS_PROFILE")]
pub profile: Option<String>,
#[arg(short = 'o', long, global = true, value_enum, default_value = "auto")]
pub output: OutputFormat,
#[arg(long, global = true)]
pub quiet: bool,
#[arg(long, global = true, hide = true)]
pub json: bool,
#[command(subcommand)]
pub command: Option<Command>,
}
#[derive(Debug, Subcommand)]
pub enum Command {
Init(InitArgs),
Auth {
#[command(subcommand)]
command: AuthCommand,
},
Whoami,
List(OffsetPageArgs),
Channels {
#[command(subcommand)]
command: ChannelsCommand,
},
Chats {
#[command(subcommand)]
command: ChatsCommand,
},
Messages {
#[command(subcommand)]
command: MessagesCommand,
},
Tui(TuiArgs),
Doctor,
Capabilities,
Schema {
#[arg(long)]
command: Option<String>,
},
Completions { shell: Shell },
}
#[derive(Debug, Args)]
pub struct InitArgs {
#[arg(long, env = "TEAMS_CLIENT_ID")]
pub client_id: Option<String>,
#[arg(long, default_value = "organizations", env = "TEAMS_TENANT")]
pub tenant: String,
#[arg(long)]
pub no_login: bool,
#[arg(long)]
pub device_code: bool,
}
#[derive(Debug, Subcommand)]
pub enum AuthCommand {
Login {
#[arg(long)]
device_code: bool,
},
Logout,
Status,
}
#[derive(Debug, Subcommand)]
pub enum ChannelsCommand {
List {
team: String,
#[command(flatten)]
page: OffsetPageArgs,
},
}
#[derive(Debug, Subcommand)]
pub enum ChatsCommand {
List(PageArgs),
}
#[derive(Debug, Args, Clone)]
pub struct PageArgs {
#[arg(long, default_value_t = 50, value_parser = clap::value_parser!(u16).range(1..=50))]
pub limit: u16,
#[arg(long)]
pub cursor: Option<String>,
#[arg(long)]
pub fields: Option<String>,
}
#[derive(Debug, Args, Clone)]
pub struct OffsetPageArgs {
#[arg(long, default_value_t = 50, value_parser = clap::value_parser!(u16).range(1..=100))]
pub limit: u16,
#[arg(long, default_value_t = 0)]
pub offset: usize,
#[arg(long)]
pub fields: Option<String>,
}
#[derive(Debug, Subcommand)]
pub enum MessagesCommand {
List {
#[arg(long, conflicts_with = "team", required_unless_present = "team")]
chat: Option<String>,
#[arg(long, requires = "channel", required_unless_present = "chat")]
team: Option<String>,
#[arg(long, requires = "team")]
channel: Option<String>,
#[command(flatten)]
page: PageArgs,
},
Send {
#[arg(long, conflicts_with = "team", required_unless_present = "team")]
chat: Option<String>,
#[arg(long, requires = "channel", required_unless_present = "chat")]
team: Option<String>,
#[arg(long, requires = "team")]
channel: Option<String>,
#[arg(long)]
body: String,
},
}
#[derive(Debug, Args)]
pub struct TuiArgs {
#[arg(long)]
pub demo: bool,
#[arg(long, requires = "demo")]
pub snapshot: bool,
#[arg(long, default_value_t = 100, hide = true)]
pub width: u16,
#[arg(long, default_value_t = 30, hide = true)]
pub height: u16,
}