diff --git a/Cargo.toml b/Cargo.toml index 3420934..7d7fbeb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pastol" -version = "2.0.1" +version = "2.0.2" authors = ["M1n-74316D65"] edition = "2021" description = "Paste.lol on the command line." diff --git a/README.md b/README.md index dce693e..60cd868 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,8 @@ help Print this message or the help of the given subcommand(s) 1. Set user and API key. ```sh pastol --setuser your_username --setapikey your_api_key + + # if the env var api_omg_lol is set it will be used instead ``` 2. Exampe as adam. diff --git a/src/main.rs b/src/main.rs index 372774a..6b70515 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use clap::error::{Error, ErrorKind}; use clap::{ArgMatches, Args as _, Command, FromArgMatches, Parser, Subcommand}; +use std::env; mod config_manager; mod deserializer; @@ -190,23 +191,41 @@ fn main() { let args = Cli::parse(); let result = deserializer::deserialized(); match result { - Ok(config) => match &args.subcommand { + Ok(mut config) => match &args.subcommand { Some(CliSub::Add(args)) => { + if let Some(val) = env::var("api_omg_lol").ok() { + config.api_key = val; + } petition_manager::add(args, config); } Some(CliSub::Search(args)) => { + if let Some(val) = env::var("api_omg_lol").ok() { + config.api_key = val; + } petition_manager::search(args, config); } Some(CliSub::Download(args)) => { + if let Some(val) = env::var("api_omg_lol").ok() { + config.api_key = val; + } petition_manager::download(args, config); } Some(CliSub::View(args)) => { + if let Some(val) = env::var("api_omg_lol").ok() { + config.api_key = val; + } petition_manager::view(args, config); } Some(CliSub::Remove(args)) => { + if let Some(val) = env::var("api_omg_lol").ok() { + config.api_key = val; + } petition_manager::remove(args, config); } Some(CliSub::List(_)) => { + if let Some(val) = env::var("api_omg_lol").ok() { + config.api_key = val; + } petition_manager::list(config); } Some(CliSub::Settings(args)) => {