cli.rs 908 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. use std::path::PathBuf;
  2. use clap::Parser;
  3. use clap::ValueEnum;
  4. #[derive(Parser, Debug)]
  5. #[command(
  6. version,
  7. about,
  8. long_about = "A compression utility for utf-8 encoded text, \
  9. using only basic canonical huffman encoding."
  10. )]
  11. pub struct Args {
  12. /// The input file to be (de)compressed.
  13. pub input_file: PathBuf,
  14. /// The optional output file for the resulting (de)compressed output.
  15. pub output_file: Option<PathBuf>,
  16. /// Whether to compress or extract.
  17. #[arg(short, value_enum)]
  18. pub mode: Option<Mode>,
  19. }
  20. #[derive(Clone, Copy, Debug, ValueEnum, Default)]
  21. pub enum Mode {
  22. /// Extract
  23. X,
  24. #[default]
  25. /// Compress
  26. C,
  27. }
  28. impl From<Mode> for clap::builder::OsStr {
  29. fn from(val: Mode) -> Self {
  30. match val {
  31. Mode::X => clap::builder::OsStr::from("x"),
  32. Mode::C => clap::builder::OsStr::from("c"),
  33. }
  34. }
  35. }