use std::path::Path;
use clap::Parser;
use hermit::Error;
use reverie::process::ExitStatus;
use super::global_opts::GlobalOpts;
use crate::clean::CleanOpts;
use crate::list::ListOpts;
use crate::record_start::StartOpts;
use crate::remove::RemoveOpts;
#[derive(Debug, Parser)]
#[clap(args_conflicts_with_subcommands = true, subcommand_negates_reqs = true)]
pub struct RecordOpts {
#[clap(subcommand)]
record_command: Option<RecordCommand>,
#[clap(flatten)]
start: StartOpts,
}
#[derive(Debug, Parser)]
enum RecordCommand {
#[clap(name = "list", alias = "ls")]
List(ListOpts),
#[clap(name = "rm", alias = "remove")]
Remove(RemoveOpts),
#[clap(name = "clean")]
Clean(CleanOpts),
#[clap(name = "start")]
Start(Box<StartOpts>),
}
impl RecordOpts {
pub fn starts_recording(&self) -> bool {
matches!(self.record_command, None | Some(RecordCommand::Start(_)))
}
pub(crate) fn verify_json_path(&self) -> Option<&Path> {
match &self.record_command {
Some(RecordCommand::Start(start)) => start.verify_json_path(),
Some(_) => None,
None => self.start.verify_json_path(),
}
}
pub fn main(&self, global: &GlobalOpts) -> Result<ExitStatus, Error> {
match &self.record_command {
Some(RecordCommand::List(x)) => x.main(global),
Some(RecordCommand::Remove(x)) => x.main(global),
Some(RecordCommand::Clean(x)) => x.main(global),
Some(RecordCommand::Start(x)) => x.main(global),
None => self.start.main(global),
}
}
}