initial console input logic

This commit is contained in:
Gonçalo Valério 2022-11-23 22:28:52 +00:00
parent ba16885ab7
commit 56fb037fa8
Signed by: dethos
GPG Key ID: DF557F2BDCC2445E
3 changed files with 55 additions and 1 deletions

11
Cargo.lock generated
View File

@ -332,6 +332,7 @@ version = "0.1.0"
dependencies = [
"clap",
"reqwest",
"rpassword",
]
[[package]]
@ -560,6 +561,16 @@ dependencies = [
"winreg",
]
[[package]]
name = "rpassword"
version = "7.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20c9f5d2a0c3e2ea729ab3706d22217177770654c3ef5056b68b69d07332d3f5"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "ryu"
version = "1.0.11"

View File

@ -8,3 +8,4 @@ edition = "2021"
[dependencies]
clap = "4"
reqwest = "0.11"
rpassword = "7.0"

View File

@ -1,3 +1,45 @@
use clap::{Arg, ArgAction, Command};
use rpassword;
use std::env;
use std::process;
fn main() {
println!("Hello, world!");
let matches = Command::new("jacanaoesta")
.version("0.1.0")
.author("Gonçalo Valério <gon@ovalerio.net>")
.about("Find people that are no longer active in your Mastodon follow list.")
.arg(Arg::new("instance").required(true))
.arg(
Arg::new("api-key")
.short('k')
.long("api-key")
.help("Ask for API key")
.action(ArgAction::SetTrue),
)
.get_matches();
let ask_for_key = matches.get_flag("api-key");
let api_key = match get_api_key(ask_for_key) {
Ok(key) => key,
_ => {
println!("Could not find a valid API Key");
process::exit(1);
}
};
// TODO
}
fn get_api_key(ask: bool) -> Result<String, ()> {
if ask {
match rpassword::prompt_password("Paste API Key here:") {
Ok(key) => return Ok(key),
_ => Err(()),
}
} else {
match env::var("JCNE_MAST_API_KEY") {
Ok(key) => return Ok(key),
_ => Err(()),
}
}
}