making it usable from cli
This commit is contained in:
parent
c97dfaa163
commit
7caf914a26
39
src/args.rs
39
src/args.rs
@ -0,0 +1,39 @@
|
||||
use clap::{Parser, ValueEnum};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about)]
|
||||
pub struct Args {
|
||||
#[arg(long, value_enum, required = true)]
|
||||
pub mode: Mode,
|
||||
|
||||
#[arg(
|
||||
short,
|
||||
long,
|
||||
required = true,
|
||||
)]
|
||||
pub input_file: Option<String>,
|
||||
|
||||
#[arg(
|
||||
short,
|
||||
long,
|
||||
required_if_eq("mode", "Mode::Encode"),
|
||||
required_if_eq("mode", "Mode::Decode"),
|
||||
required_if_eq("mode", "Mode::Remove")
|
||||
)]
|
||||
pub chunk_type: Option<String>,
|
||||
|
||||
#[arg(
|
||||
short,
|
||||
long,
|
||||
required_if_eq("mode", "Mode::Encode")
|
||||
)]
|
||||
pub message: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
|
||||
pub enum Mode {
|
||||
Encode,
|
||||
Decode,
|
||||
Print,
|
||||
Remove
|
||||
}
|
51
src/main.rs
51
src/main.rs
@ -4,9 +4,58 @@ mod chunk_type;
|
||||
mod commands;
|
||||
mod png;
|
||||
|
||||
use core::panic;
|
||||
use std::path::PathBuf;
|
||||
use std::fs::File;
|
||||
|
||||
use args::Mode;
|
||||
use chunk_type::ChunkType;
|
||||
use clap::Parser;
|
||||
use crate::args::Args;
|
||||
|
||||
pub type Error = Box<dyn std::error::Error>;
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
fn get_image(path: &str) -> File {
|
||||
let image_path: PathBuf = PathBuf::from(path);
|
||||
let path_display = image_path.display();
|
||||
|
||||
let image = match File::open(&image_path) {
|
||||
Err(why) => panic!("couldn't open {}: {}", path_display, why),
|
||||
Ok(file) => file
|
||||
};
|
||||
|
||||
image
|
||||
}
|
||||
|
||||
fn encode(image: File, chunk_type: ChunkType, message: &str) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn decode(image: File, chunk_type: ChunkType) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn print_message(image: File) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn remove_message(image: File, chunk_type: ChunkType) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse();
|
||||
|
||||
let image = get_image(&args.input_file.unwrap());
|
||||
|
||||
match args.mode {
|
||||
Mode::Encode => todo!(),
|
||||
Mode::Decode => todo!(),
|
||||
Mode::Print => todo!(),
|
||||
Mode::Remove => todo!(),
|
||||
_ => Err("not a valid mode")?
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user