use clap::{Args, Parser, Subcommand};
use clap_complete::engine::ArgValueCandidates;
use crate::workspace;
#[derive(Parser)]
#[command(name = "workon", version, about = "Development workspace launcher with Zellij")]
#[command(args_conflicts_with_subcommands = true)]
pub struct Cli {
#[command(subcommand)]
pub command: Option<Command>,
#[command(flatten)]
pub session: SessionArgs,
}
#[derive(Args)]
#[allow(clippy::struct_excessive_bools)]
pub struct SessionArgs {
#[arg(long)]
pub name: Option<String>,
#[arg(short = 'w')]
pub workspace: bool,
#[arg(long, conflicts_with = "workspace")]
pub new_session: bool,
#[arg(long, requires = "workspace")]
pub skip_copy_ignored: bool,
#[arg(short = 'r', long, requires = "workspace")]
pub resume: Option<String>,
#[arg(short = 'c', long = "config")]
pub config: Option<String>,
#[arg(short = 'n', hide = true)]
pub reserved_n: bool,
}
#[derive(Subcommand)]
pub enum Command {
Create {
#[arg(long)]
name: Option<String>,
#[arg(short = 'c', long = "config")]
config: Option<String>,
#[arg(long)]
skip_copy_ignored: bool,
#[arg(long)]
json: bool,
},
Attach {
#[arg(add = ArgValueCandidates::new(workspace::ref_candidates))]
reference: Option<String>,
#[arg(short = 'c', long = "config")]
config: Option<String>,
},
Destroy {
#[arg(add = ArgValueCandidates::new(workspace::ref_candidates))]
reference: Option<String>,
#[arg(long)]
no_save: bool,
#[arg(long)]
json: bool,
},
List {
#[arg(long)]
json: bool,
},
Path {
#[arg(add = ArgValueCandidates::new(workspace::ref_candidates))]
reference: Option<String>,
},
}
pub fn given_name(name: Option<&str>) -> Option<&str> {
name.filter(|s| !s.is_empty())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn empty_name_is_no_name() {
assert_eq!(given_name(Some("fix-bug")), Some("fix-bug"));
assert_eq!(given_name(Some("")), None);
assert_eq!(given_name(None), None);
}
}