From 408b0108a512e307883cd83b33dcce0a24fdf9d4 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Sat, 24 May 2025 13:52:32 -0500 Subject: [PATCH] Starting the Clap CLI parser --- Cargo.toml | 2 +- src/cli.rs | 24 ++++++++++++++++++++++++ src/lib.rs | 2 ++ src/main.rs | 11 ++++++++++- 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 src/cli.rs diff --git a/Cargo.toml b/Cargo.toml index 7f85ab2..c73893a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2024" [dependencies] -clap = "4.0.32" +clap = { version = "4.0.7", features = ["derive"] } reqwest = { version = "0.11.13", features = ["json"] } serde = { version = "1.0.152", features = ["derive"] } tokio = { version = "1.24.2", features = ["macros", "rt-multi-thread"] } diff --git a/src/cli.rs b/src/cli.rs new file mode 100644 index 0000000..7b3cf4d --- /dev/null +++ b/src/cli.rs @@ -0,0 +1,24 @@ +use clap::{ + Parser, + Subcommand +}; + +#[derive(Parser, Debug)] +#[command(version, about, long_about = None)] +pub struct Args { + #[arg(short = 'o', long = "owner")] + repo_owner: Option, + #[arg(short = 'n', long = "repo_name")] + repo_name: Option, + + #[command(subcommand)] + command: Option +} + +#[derive(Subcommand, Debug)] +enum Commands { + ListReleases{ + #[arg(short, long)] + list: bool, + }, +} diff --git a/src/lib.rs b/src/lib.rs index ace7e6f..c40eca3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,7 @@ use serde::Deserialize; +pub mod cli; + pub fn module_echo(){ println!("hello from lib.rs!"); } diff --git a/src/main.rs b/src/main.rs index 395f581..14820ed 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,9 @@ -use gt_tools::ReleaseInfo; +use gt_tools::{ + ReleaseInfo, + cli::Args +}; + +use clap::Parser; use reqwest::Error; use reqwest::header::{ @@ -8,6 +13,10 @@ use reqwest::header::{ #[tokio::main] async fn main() -> Result<(), Error> { + let args = Args::parse(); + + println!("{:?}", args); + let request_url = format!( "http:/localhost:3000/api/v1/repos/{owner}/{repo}/releases", owner = "robert",