use crate::cli::completer;
use crate::cli::parser;
use clap::{Args, Parser, Subcommand};
use clap_verbosity_flag::InfoLevel;
use serde::{Deserialize, Serialize};
#[derive(Parser)]
#[command(version)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
#[command(flatten)]
pub verbose: clap_verbosity_flag::Verbosity<InfoLevel>,
}
#[derive(Subcommand)]
pub enum Commands {
Config {
#[command(subcommand)]
command: ConfigCommands,
},
Track {
#[command(subcommand)]
command: TimeTrackCommands,
},
Server {
#[command(subcommand)]
command: ServerCommands,
},
}
#[derive(Subcommand)]
pub enum ConfigCommands {
Get(ConfigGetArgs),
Set(ConfigSetArgs),
}
#[derive(Args)]
pub struct ConfigGetArgs {
pub option: ConfigurationOption,
}
#[derive(Args)]
pub struct ConfigSetArgs {
pub option: ConfigurationOption,
pub value: String,
}
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone, clap::ValueEnum)]
pub enum ConfigurationOption {
ActivitiesFetchIntervalSeconds,
ProjectsFetchIntervalSeconds,
IssuesFetchIntervalSeconds,
FetchRetriesMaximum,
}
#[derive(Subcommand)]
pub enum TimeTrackCommands {
Start(TrackStartArgs),
Stop(TrackStopArgs),
Show(TrackShowArgs),
}
#[derive(Args)]
pub struct TrackStartArgs {
#[command(flatten)]
pub server_selection: ServerSelectionArgs,
#[arg(short, long)]
pub activity: Option<String>,
#[arg(short, long, conflicts_with = "issue")]
pub project: Option<String>,
#[arg(short, long, conflicts_with = "project")]
pub issue: Option<String>,
#[arg(short, long, conflicts_with = "project")]
pub comment: Option<String>,
#[arg(short = 'C', long)]
pub ignore_cache: bool,
}
#[derive(Args)]
pub struct TrackStopArgs {
#[command(flatten)]
pub server_selection: ServerSelectionArgs,
pub secret_path: Option<String>,
}
#[derive(Args)]
pub struct TrackShowArgs {
#[command(flatten)]
pub server_selection: ServerSelectionArgs,
}
#[derive(Subcommand)]
pub enum ServerCommands {
Add(ServerAddArgs),
List(ServerListArgs),
Remove(ServerRemoveArgs),
SetDefault(ServerSetDefaultArgs),
}
#[derive(Args)]
pub struct ServerAddArgs {
#[arg(short, long)]
pub name: Option<String>,
#[command(flatten)]
pub token: ServerToken,
#[arg(short, long)]
pub default: bool,
pub url: String,
}
#[derive(Args)]
#[group(required = true, multiple = false)]
pub struct ServerToken {
#[arg(short, long, conflicts_with = "command")]
pub token: Option<String>,
#[arg(short, long, conflicts_with = "token")]
pub command: Option<String>,
}
#[derive(Args)]
pub struct ServerRemoveArgs {
#[command(flatten)]
pub server_selection: ServerSelectionArgs,
}
#[derive(Args)]
pub struct ServerSetDefaultArgs {
#[arg(value_parser = parser::server_name)]
pub name: String,
}
#[derive(Args)]
pub struct ServerListArgs {}
#[derive(Args)]
pub struct ServerSelectionArgs {
#[arg(short, long, add = completer::server_name(), value_parser = parser::server_name)]
pub server: Option<String>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn verify_cli() {
use clap::CommandFactory;
Cli::command().debug_assert();
}
}