Pārlūkot izejas kodu

Changed CLI flags

AvariceLHubris 3 nedēļas atpakaļ
vecāks
revīzija
a9154346e7
2 mainītis faili ar 17 papildinājumiem un 19 dzēšanām
  1. 10 18
      src/cli.rs
  2. 7 1
      src/main.rs

+ 10 - 18
src/cli.rs

@@ -1,7 +1,6 @@
 use std::path::PathBuf;
 
 use clap::Parser;
-use clap::ValueEnum;
 
 #[derive(Parser, Debug)]
 #[command(
@@ -11,31 +10,24 @@ use clap::ValueEnum;
     using only basic canonical huffman encoding."
 )]
 pub struct Args {
-    /// The input file to be (de)compressed.
+    /// Input file to (de)compress, or '-' to read from stdin
     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>,
 
-    /// 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 {
-    /// Extract
     X,
     #[default]
-    /// Compress
     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"),
-        }
-    }
-}

+ 7 - 1
src/main.rs

@@ -11,7 +11,13 @@ fn main() -> Result<(), anyhow::Error> {
 
     let inputf = args.input_file;
     let outputf = args.output_file;
-    let mode = args.mode;
+    let mode = if args.compress {
+        Some(cli::Mode::C)
+    } else if args.extract {
+        Some(cli::Mode::X)
+    } else {
+        None
+    };
 
     let is_stdin = inputf == Path::new("-");