use clap::{Parser, Subcommand};
use postmodern::job::JobStatus;
use uuid_suffix::UuidSuffix;
#[derive(Debug, Parser)]
#[command(version)]
pub struct Cli {
#[arg(long, global = true)]
pub db: Option<String>,
#[command(subcommand)]
pub command: Command,
}
#[derive(Debug, Subcommand)]
pub enum Command {
Queue {
#[command(subcommand)]
command: QueueCommand,
},
Job {
#[command(subcommand)]
command: JobCommand,
},
Db {
#[command(subcommand)]
command: DbCommand,
},
Pg {
#[command(subcommand)]
command: PgCommand,
},
}
#[derive(Debug, Subcommand)]
pub enum QueueCommand {
Ls,
Create {
queue: String,
#[arg(long)]
paused: bool,
},
Delete {
queue: String,
},
Pause {
queue: String,
},
Resume {
queue: String,
},
}
#[derive(Debug, Subcommand)]
pub enum JobCommand {
Ls {
#[arg(long, short)]
queue: Option<String>,
#[arg(long, short)]
status: Option<JobStatusArg>,
#[arg(long, short, default_value = "100")]
limit: u32,
},
Show {
id: UuidSuffix,
},
Next {
queue: String,
#[arg(long, conflicts_with = "ack")]
peek: bool,
#[arg(long, conflicts_with = "peek")]
ack: bool,
},
Move {
id: Vec<UuidSuffix>,
#[arg(long, short = 't')]
to: String,
},
Copy {
id: UuidSuffix,
#[arg(long, short = 't')]
to: String,
},
Restart {
id: Vec<UuidSuffix>,
#[arg(long)]
force: bool,
},
Delete {
id: Vec<UuidSuffix>,
},
Fail {
id: Vec<UuidSuffix>,
#[arg(long, short)]
message: String,
},
Done {
id: Vec<UuidSuffix>,
},
Search {
pattern: String,
#[arg(long, short)]
queue: Option<String>,
#[arg(long, short)]
status: Option<JobStatusArg>,
#[arg(long)]
no_limit: bool,
},
Get {
path: String,
id: UuidSuffix,
},
}
#[derive(Debug, Subcommand)]
pub enum DbCommand {
Stats,
Reap,
}
#[derive(Debug, Subcommand)]
pub enum PgCommand {
Backup,
Restore,
}
#[derive(Clone, Copy, Debug)]
pub enum JobStatusArg {
Pending,
Paused,
InProgress,
Finished,
Failed,
}
impl std::str::FromStr for JobStatusArg {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"pending" => Ok(Self::Pending),
"paused" => Ok(Self::Paused),
"in-progress" => Ok(Self::InProgress),
"finished" => Ok(Self::Finished),
"failed" => Ok(Self::Failed),
_ => Err(format!("unknown status: {s}")),
}
}
}
impl From<JobStatusArg> for JobStatus {
fn from(arg: JobStatusArg) -> Self {
match arg {
JobStatusArg::Pending => JobStatus::Pending,
JobStatusArg::Paused => JobStatus::Paused,
JobStatusArg::InProgress => JobStatus::InProgress,
JobStatusArg::Finished => JobStatus::Finished,
JobStatusArg::Failed => JobStatus::Failed,
}
}
}