From 8b0f60d348b6ebfda48035c5be82c14a77e661e3 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Sat, 24 May 2025 14:18:38 -0500 Subject: [PATCH] Wire in the ListReleases primary command Hey, look at that. I can do the thing what with the stuff and such. --- src/cli.rs | 15 ++++++--------- src/lib.rs | 6 +++--- src/main.rs | 45 +++++++++++++++++++++------------------------ 3 files changed, 30 insertions(+), 36 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 7b3cf4d..8489d95 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,23 +1,20 @@ -use clap::{ - Parser, - Subcommand -}; +use clap::{Parser, Subcommand}; #[derive(Parser, Debug)] #[command(version, about, long_about = None)] pub struct Args { #[arg(short = 'o', long = "owner")] - repo_owner: Option, + pub repo_owner: Option, #[arg(short = 'n', long = "repo_name")] - repo_name: Option, + pub repo_name: Option, #[command(subcommand)] - command: Option + pub command: Commands, } #[derive(Subcommand, Debug)] -enum Commands { - ListReleases{ +pub enum Commands { + ListReleases { #[arg(short, long)] list: bool, }, diff --git a/src/lib.rs b/src/lib.rs index c40eca3..22cd116 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,7 @@ use serde::Deserialize; pub mod cli; -pub fn module_echo(){ +pub fn module_echo() { println!("hello from lib.rs!"); } @@ -23,7 +23,7 @@ pub struct ReleaseInfo { prerelease: bool, created_at: String, published_at: String, - author: Author + author: Author, } #[derive(Deserialize, Debug)] @@ -33,5 +33,5 @@ pub struct Author { login_name: String, source_id: usize, full_name: String, - email: String + email: String, } diff --git a/src/main.rs b/src/main.rs index 14820ed..5aa885c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,36 +1,33 @@ -use gt_tools::{ - ReleaseInfo, - cli::Args -}; +use gt_tools::{ReleaseInfo, cli::Args}; use clap::Parser; use reqwest::Error; -use reqwest::header::{ - USER_AGENT, - ACCEPT -}; +use reqwest::header::{ACCEPT, USER_AGENT}; #[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", - repo = "rcalc", - ); - let client = reqwest::Client::new(); - let response = client - .get(request_url) - .header(USER_AGENT, "gt-tools-test-agent") - .header(ACCEPT, "application/json") - .send() - .await?; - let body_text: Vec = response.json().await?; + match args.command { + gt_tools::cli::Commands::ListReleases { list } => { + let request_url = format!( + "http:/localhost:3000/api/v1/repos/{owner}/{repo}/releases", + owner = "robert", + repo = "rcalc", + ); + let client = reqwest::Client::new(); + let response = client + .get(request_url) + .header(USER_AGENT, "gt-tools-test-agent") + .header(ACCEPT, "application/json") + .send() + .await?; + let body_text: Vec = response.json().await?; + + println!("{:?}", body_text); + } + } - println!("{:?}", body_text); Ok(()) }