parent
295f0a1bcd
commit
fd2ad0fdb4
@ -0,0 +1,65 @@
|
|||||||
|
use std::{fmt,error};
|
||||||
|
|
||||||
|
/// Print help message then exit with code `2`.
|
||||||
|
pub fn usage() -> !
|
||||||
|
{
|
||||||
|
eprintln!("uasge: {} <output file> <input files...>", std::env::args().next().unwrap());
|
||||||
|
|
||||||
|
eprintln!();
|
||||||
|
eprintln!("mapcat v{}: mmap() based file concatenation", env!("CARGO_PKG_VERSION"));
|
||||||
|
eprintln!(" by {} with <3 (licensed GPL3+)", env!("CARGO_PKG_AUTHORS"));
|
||||||
|
eprintln!();
|
||||||
|
|
||||||
|
eprintln!("NOTES:");
|
||||||
|
eprintln!("The output file is required, if one is not provided, we will just print this message and exit with error code `2`. If there are no input files, it will just create an empty output and return with error code `0` (unless there were other errors)");
|
||||||
|
eprintln!("Output files are always clobbered regardless if there are any inputs, or if the concatenation operation succeeds / fails");
|
||||||
|
eprintln!();
|
||||||
|
eprintln!(" (compiled with write parallelisation enabled)"); //TODO: we will eventually feature gate the threaded scheduler based solution. but for now, it is the only one implemented so we'll just print this always
|
||||||
|
|
||||||
|
std::process::exit(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
pub struct Operation
|
||||||
|
{
|
||||||
|
pub output: String,
|
||||||
|
pub inputs: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parse the arguments passed to the process
|
||||||
|
#[inline] pub fn parse_args() -> Result<Operation, ArgParseError>
|
||||||
|
{
|
||||||
|
parse(std::env::args().skip(1))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parse<J: Into<String>, I: IntoIterator<Item = J>>(args: I) -> Result<Operation, ArgParseError>
|
||||||
|
{
|
||||||
|
let mut args = args.into_iter().map(Into::into);
|
||||||
|
|
||||||
|
let output = args.next().ok_or(ArgParseError::NoOutput)?;
|
||||||
|
|
||||||
|
Ok(
|
||||||
|
Operation {
|
||||||
|
output,
|
||||||
|
inputs: args.collect(),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum ArgParseError
|
||||||
|
{
|
||||||
|
NoOutput,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl error::Error for ArgParseError{}
|
||||||
|
impl fmt::Display for ArgParseError
|
||||||
|
{
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
||||||
|
{
|
||||||
|
match self {
|
||||||
|
Self::NoOutput => write!(f, "output file was not provided"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in new issue