From 2aa77384a0125cc7378ac6b36f8c468b74b2ad05 Mon Sep 17 00:00:00 2001 From: Saumit Dinesan Date: Tue, 14 Jun 2022 18:23:39 +0530 Subject: Using clap - command line argument parser --- src/main.rs | 25 +++++++++++++++++++------ 1 file 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(); +} + + -- cgit v1.2.3