summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaumit Dinesan <justsaumit@protonmail.com>2022-06-14 18:23:39 +0530
committerSaumit Dinesan <justsaumit@protonmail.com>2022-06-14 18:23:39 +0530
commit2aa77384a0125cc7378ac6b36f8c468b74b2ad05 (patch)
tree530bdbd7c2b52c149a76886bfd0b4e899e09ac32
parent84f0f259ddba119666bf5b257c8b07f9cc28391c (diff)
Using clap - command line argument parser
-rw-r--r--src/main.rs25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs
index 423a643..6bb5758 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,19 @@
-let pattern = std::env::args().nth(1).expect("no pattern given");
-let path = std::env::args().nth(2).expect("no path given");
-let args = Cli {
- pattern: pattern,
- path: std::path::PathBuf::from(path),
-};
+#![allow(unused)]
+///Using clap - command line argument parser
+use clap::Parser;
+
+/// Search for a pattern in a file and display the lines that contain it.
+#[derive(Parser)]
+struct Cli {
+ /// The pattern to look for
+ pattern: String,
+ /// The path to the file to read
+ #[clap(parse(from_os_str))]
+ path: std::path::PathBuf,
+}
+
+fn main() {
+ let args = Cli::parse();
+}
+
+