From dbad76baac9911d692ebc78335cbc51554443344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Sat, 11 Jan 2020 15:00:15 -0700 Subject: Parse command line arguments --- .gitlab-ci.yml | 2 +- Cargo.toml | 1 + src/main.rs | 14 +++++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cb84891..04b81b1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,7 +6,7 @@ rust-latest: image: rust:latest script: - cargo build --verbose - - cargo run + - cargo run -- s 5 - cargo test --verbose rust-nightly: diff --git a/Cargo.toml b/Cargo.toml index a7cf602..868f563 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,4 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +structopt = "0.3.7" diff --git a/src/main.rs b/src/main.rs index e7a11a9..4277e8c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,15 @@ +use structopt::StructOpt; + +#[derive(Debug, StructOpt)] +struct Cli { + /// The pattern to look for + pattern: String, + /// The path to the file to read + #[structopt(parse(from_os_str))] + path: std::path::PathBuf, +} + fn main() { - println!("Hello, world!"); + let args = Cli::from_args(); + println!("{:?}", args); } -- cgit v1.2.3 From d7d33b6a00908271cc3f6d2fccd8f6bcf30154da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Sat, 11 Jan 2020 15:09:57 -0700 Subject: Print help --- .gitlab-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 04b81b1..09e53ff 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,8 +6,9 @@ rust-latest: image: rust:latest script: - cargo build --verbose - - cargo run -- s 5 - cargo test --verbose + - cargo run -- -h + - cargo run -- s 5 rust-nightly: stage: build -- cgit v1.2.3