TYK5XDMD7PSITQFFPHNLD3462EODC3FQIV5DCW5KA527FXIW7CTQC
MAPKBZYGUKQLVJQO42NESR2U7RNM3F3ZPNQ7X45EHAKW2FQWCZ7AC
MPE26QJ2WFCD3OKXZJ6C2VSF6E6UVLUNB6ORODFZOASMZLGQSUUQC
V2GAFFJH2YQJSG3CDQL2K6GWG7N73F33C3KXDFNYM3YNK4TZ3XLQC
SY4Q66QFFEQ2BPMJ5G7MSZPX52HM6QTHZXJWL2VVFB2JMWZQLJBQC
5GJRHBKCSWISBPJOAXWMXY3LMMD5GFOEHM3AEUKI5J7D4M3XM5GQC
3JRIW3OEB5GC4QRICM5JRRRMKTQPM6VMBC5YTVPIA6ERWHNAIORQC
FANJLREUGPFYMGW5DJ4YNQWQB5LMORUVMSEOFAWVFNMFXVXZI3NAC
7VF7R445O5YJ6AWMKF7DM3AP75E6LGVVDHICXFQUXWRYP22PVWFAC
FVJQ6OJYLCXGPDNHCP56JXZ44VQKFIOC7NC3S42D3JPQSZ2F7R4AC
EHKSDEXADHIK2PFXJFBFQTAUAXBUIY57CKSDNLCQJH3WKPNHG6RAC
3PGX7SVOAB5DOZFA7OGREPZZEWSD4LXNTA6AQYYPTQO6AXVQHKMQC
}
#[derive(serde::Deserialize)]
struct Processor {
path: PathBuf,
command: String,
args: Vec<String>,
}
#[derive(serde::Deserialize)]
struct Config {
processors: Vec<Processor>,
}
fn process(filename: &Path, command: &str, args: &[String]) -> Result<(), Box<dyn Error>> {
let queue_dir = filename.parent().unwrap().join(".queue");
fs::create_dir_all(&queue_dir)?;
let newname = queue_dir.join(filename.file_name().unwrap());
println!("Queueing at {:?}", newname);
fs::rename(&filename, &newname)?;
Command::new(command)
.args(args)
.arg(&newname)
.status()?
.exit_ok()?;
println!("Removing {:?}", &newname);
fs::remove_file(&newname)?;
Ok(())
fn parse_config() -> Result<Config, Box<dyn Error>> {
let config_path = directories::BaseDirs::new()
.and_then(|bd| Some(bd.config_dir().to_owned()))
.unwrap_or(PathBuf::from("."))
.join("nfp")
.join("config.toml");
let mut config_str = String::new();
fs::File::open(config_path)?.read_to_string(&mut config_str)?;
Ok(toml::from_str(&config_str)?)
fn process(filename: &Path, command: &str, args: &[String]) -> Result<(), Box<dyn Error>> {
let queue_dir = filename.parent().unwrap().join(".queue");
fs::create_dir_all(&queue_dir)?;
let newname = queue_dir.join(filename.file_name().unwrap());
println!("Queueing at {:?}", newname);
fs::rename(&filename, &newname)?;
Command::new(command)
.args(args)
.arg(&newname)
.status()?
.exit_ok()?;
println!("Removing {:?}", &newname);
fs::remove_file(&newname)?;
Ok(())
use std::error::Error;
use std::fs;
use std::io::Read;
use std::path::PathBuf;
#[derive(serde::Deserialize)]
pub struct Processor {
pub path: PathBuf,
pub command: String,
pub args: Vec<String>,
}
#[derive(serde::Deserialize)]
pub struct Config {
pub processors: Vec<Processor>,
}
impl Config {
pub fn parse() -> Result<Self, Box<dyn Error>> {
let config_path = directories::BaseDirs::new()
.and_then(|bd| Some(bd.config_dir().to_owned()))
.unwrap_or(PathBuf::from("."))
.join("nfp")
.join("config.toml");
let mut config_str = String::new();
fs::File::open(config_path)?.read_to_string(&mut config_str)?;
Ok(toml::from_str(&config_str)?)
}
}