|
@@ -1,7 +1,6 @@
|
|
|
use std::path::PathBuf;
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
use clap::Parser;
|
|
use clap::Parser;
|
|
|
-use clap::ValueEnum;
|
|
|
|
|
|
|
|
|
|
#[derive(Parser, Debug)]
|
|
#[derive(Parser, Debug)]
|
|
|
#[command(
|
|
#[command(
|
|
@@ -11,31 +10,24 @@ use clap::ValueEnum;
|
|
|
using only basic canonical huffman encoding."
|
|
using only basic canonical huffman encoding."
|
|
|
)]
|
|
)]
|
|
|
pub struct Args {
|
|
pub struct Args {
|
|
|
- /// The input file to be (de)compressed.
|
|
|
|
|
|
|
+ /// Input file to (de)compress, or '-' to read from stdin
|
|
|
pub input_file: PathBuf,
|
|
pub input_file: PathBuf,
|
|
|
|
|
|
|
|
- /// The optional output file for the resulting (de)compressed output.
|
|
|
|
|
|
|
+ /// Output file for the resulting (de)compressed data
|
|
|
pub output_file: Option<PathBuf>,
|
|
pub output_file: Option<PathBuf>,
|
|
|
|
|
|
|
|
- /// Whether to compress or extract.
|
|
|
|
|
- #[arg(short, value_enum)]
|
|
|
|
|
- pub mode: Option<Mode>,
|
|
|
|
|
|
|
+ /// Compress the input (default when input does not end in .z)
|
|
|
|
|
+ #[arg(short = 'c', group = "mode")]
|
|
|
|
|
+ pub compress: bool,
|
|
|
|
|
+
|
|
|
|
|
+ /// Extract (decompress) the input (default when input ends in .z)
|
|
|
|
|
+ #[arg(short = 'x', group = "mode")]
|
|
|
|
|
+ pub extract: bool,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-#[derive(Clone, Copy, Debug, ValueEnum, Default)]
|
|
|
|
|
|
|
+#[derive(Clone, Copy, Debug, Default)]
|
|
|
pub enum Mode {
|
|
pub enum Mode {
|
|
|
- /// Extract
|
|
|
|
|
X,
|
|
X,
|
|
|
#[default]
|
|
#[default]
|
|
|
- /// Compress
|
|
|
|
|
C,
|
|
C,
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-impl From<Mode> for clap::builder::OsStr {
|
|
|
|
|
- fn from(val: Mode) -> Self {
|
|
|
|
|
- match val {
|
|
|
|
|
- Mode::X => clap::builder::OsStr::from("x"),
|
|
|
|
|
- Mode::C => clap::builder::OsStr::from("c"),
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|