From c658befe61af654aecc23bb07c95348a631a94a1 Mon Sep 17 00:00:00 2001 From: Harlley Date: Fri, 21 Jul 2023 10:37:43 -0300 Subject: [PATCH] fix: error with arguments --- src/main.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index afcf2b9..d9b12d6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use serde_derive::Deserialize; use reqwest::Error; +use std::env; #[derive(Deserialize, Debug)] struct Summoner { @@ -17,13 +18,13 @@ struct Summoner { async fn main() -> Result<(), Error> { let api_key = std::env::var("RIOT_API_KEY").expect("RIOT_API_KEY is not set"); - println!("Enter a summoner name: "); + let args: Vec = env::args().collect(); + if args.len() < 2 { + eprintln!("Please provide a summoner name as the first argument!"); + std::process::exit(1); + } - let mut summoner_name = String::new(); - std::io::stdin().read_line(&mut summoner_name) - .expect("Failed to read line"); - - summoner_name = summoner_name.trim().to_string(); + let summoner_name = &args[1]; let summoner_url = format!( "https://br1.api.riotgames.com/lol/summoner/v4/summoners/by-name/{}?api_key={}",