use clap::{Parser, Subcommand, Args};
#[derive(Parser)]
#[command(author, version, about)]
pub struct CLI {
#[command(subcommand)]
pub command: Option<Commands>,
#[arg(short, long, value_name = "COMPILER_NAME")]
pub compiler: Option<String>,
#[arg(short, long, value_name = "EXECUTABLE_NAME")]
pub executable: Option<String>,
#[arg(short, long)]
math: bool,
#[arg(short, long)]
thread: bool,
#[arg(short = 'r', long)]
crypto: bool,
#[arg(long)]
cunit: bool,
#[arg(long)]
cppunit: bool,
}
#[derive(Subcommand)]
pub enum Commands {
Java,
SetCompiler(NameArgument),
SetExecutable(NameArgument),
Default,
}
#[derive(Args)]
#[group(required = true)]
pub struct NameArgument {
pub name: String,
}
impl CLI {
pub fn subcommands_provided(&self) -> bool {
self.command.is_some()
}
pub fn flags_provided(&self) -> bool {
self.executable.is_some() || self.compiler.is_some()
}
pub fn parse_flags(&self) -> (String, String) {
let mut lflags = String::from("");
let mut ldlibs = String::from("");
if self.thread { lflags.push_str("-lpthread "); }
if self.math { lflags.push_str("-lm"); }
if self.cunit { ldlibs.push_str("-lcunit "); }
if self.cppunit { ldlibs.push_str("-lcppunit "); }
if self.crypto { ldlibs.push_str("-lcrypto"); }
(lflags.trim_end().to_string(), ldlibs.trim_end().to_string())
}
}