Compare commits
3 Commits
75102014fc
...
7caf914a26
Author | SHA1 | Date | |
---|---|---|---|
7caf914a26 | |||
c97dfaa163 | |||
b2bd1a9df7 |
54
Cargo.lock
generated
54
Cargo.lock
generated
@ -58,6 +58,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -72,6 +73,18 @@ dependencies = [
|
||||
"strsim",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.5.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.7.2"
|
||||
@ -99,6 +112,12 @@ version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "is_terminal_polyfill"
|
||||
version = "1.70.1"
|
||||
@ -113,12 +132,47 @@ dependencies = [
|
||||
"crc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.89"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.85"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5023162dfcd14ef8f32034d8bcd4cc5ddc61ef7a247c024a33e24e1f24d21b56"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"
|
||||
|
||||
[[package]]
|
||||
name = "utf8parse"
|
||||
version = "0.2.2"
|
||||
|
@ -5,4 +5,4 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
crc = "3.2.1"
|
||||
clap = "4.5.20"
|
||||
clap = { version = "4.5.20", features = ["derive"] }
|
||||
|
BIN
images/dices.png
Normal file
BIN
images/dices.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 140 KiB |
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