use crate::cmd::cmd_exec::{ProcessOpts, QueueProcessOpts};
use crate::cmd::cmd_prepare::{PrepareOpts, SFOpts, SFSetOpts};
use crate::cmd::cmd_queue::{
QueueInitOpts, QueueJobOpts, QueueOpts, QueueOptsWithDecoder, QueueSetSeqOpts,
};
use clap::{Args, Parser, Subcommand};
use tracing::*;
use uuid::Uuid;
pub mod cmd_exec;
pub mod cmd_info;
pub mod cmd_prepare;
pub mod cmd_queue;
#[derive(Debug, Subcommand)]
pub enum Command {
GenUUID,
GenFilename,
Prepare(PrepareOpts),
PrepareNOP(SFOpts),
PrepareFail(SFOpts),
PrepareGetNext(SFOpts),
PrepareSetNext(SFSetOpts),
QueueProcess(QueueProcessOpts),
QueueInit(QueueInitOpts),
QueueInfo(QueueJobOpts),
QueueWrite(QueueOpts),
QueueLs(QueueOptsWithDecoder),
QueueGetNext(QueueOpts),
QueueSetNext(QueueSetSeqOpts),
QueuePayload(QueueJobOpts),
StdinInfo,
StdinPayload,
StdinProcess(ProcessOpts),
ShowLicense,
}
#[derive(Debug, Args)]
pub struct GlobalOpts {
#[arg(long, short, value_name = "LEVEL", default_value_t = Level::INFO)]
pub log_level: Level,
}
#[derive(Parser, Debug)]
#[command(author, version, about)]
pub struct Cli {
#[clap(flatten)]
pub globalopts: GlobalOpts,
#[clap(subcommand)]
pub command: Command,
}
pub fn parse() -> Cli {
Cli::parse()
}
pub static LICENSE: &str = "\
Filespooler
Copyright (C) 2022 John Goerzen <jgoerzen@complete.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
";
pub fn cmd_showlicense() -> Result<(), anyhow::Error> {
println!("{}", LICENSE);
Ok(())
}
pub fn cmd_genuuid() -> Result<(), anyhow::Error> {
let mut buf = Uuid::encode_buffer();
let uuid = Uuid::new_v4().hyphenated().encode_lower(&mut buf);
println!("{}", uuid);
Ok(())
}
pub fn cmd_genfilename() -> Result<(), anyhow::Error> {
let mut buf = Uuid::encode_buffer();
let uuid = Uuid::new_v4().hyphenated().encode_lower(&mut buf);
println!("fspl-{}.fspl", uuid);
Ok(())
}