diff --git a/q-pidon/.gitignore b/q-pidon/.gitignore new file mode 100644 index 0000000..b83d222 --- /dev/null +++ b/q-pidon/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/q-pidon/Cargo.lock b/q-pidon/Cargo.lock new file mode 100644 index 0000000..3e5a6b6 --- /dev/null +++ b/q-pidon/Cargo.lock @@ -0,0 +1,25 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "q-pidon" +version = "0.1.0" +dependencies = [ + "getopts", +] + +[[package]] +name = "unicode-width" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" diff --git a/q-pidon/Cargo.toml b/q-pidon/Cargo.toml new file mode 100644 index 0000000..5586943 --- /dev/null +++ b/q-pidon/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "q-pidon" +version = "0.1.0" +edition = "2024" + +[dependencies] +getopts = "0.2" \ No newline at end of file diff --git a/q-pidon/src/main.rs b/q-pidon/src/main.rs new file mode 100644 index 0000000..b82e16f --- /dev/null +++ b/q-pidon/src/main.rs @@ -0,0 +1,37 @@ +extern crate getopts; +use getopts::Options; +use std::env; +use std::process::ExitCode; + +fn main() -> ExitCode { + let args: Vec = env::args().collect(); + + // Define flags + let mut opts = Options::new(); + opts.optflag("h", "help", "print this help menu"); + opts.optflag("v", "version", "print version"); + opts.reqopt("t", "type", "type of data/instruction to write", "TYPE"); + opts.reqopt("v", "value", "value to write", "VALUE"); + opts.reqopt("o", "output", "output folder", "FOLDER"); + + // Print help and exit (see https://github.com/rust-lang/getopts/pull/109) + if args.contains(&String::from("-h")) || args.contains(&String::from("--help")) { + print!("{}", opts.usage(&format!("Usage: {} FILE [options]", &args[0]))); + return ExitCode::SUCCESS; + } + + if args.contains(&String::from("-v")) || args.contains(&String::from("--version")) { + print!("{} {}", &args[0], env!("CARGO_PKG_VERSION")); + return ExitCode::SUCCESS; + } + + // Parse arguments + let matches = match opts.parse(&args[1..]) { + Ok(m) => { m } + Err(f) => { panic!("{}",f.to_string()) } + }; + + + + ExitCode::SUCCESS +} \ No newline at end of file