Skip to content

Commit

Permalink
Chain verify methods
Browse files Browse the repository at this point in the history
  • Loading branch information
WardLordRuby committed Oct 20, 2024
1 parent 9e268f2 commit ac38971
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl GistResponse {
}

impl Input {
fn verify_nexus(&self) -> Result<(), Error> {
fn verify_nexus(&self) -> Result<&Self, Error> {
if self.nexus_key.is_empty() {
return Err(Error::Missing(
"Nexus api key missing. Use command 'set' to store private key",
Expand All @@ -108,26 +108,26 @@ impl Input {
ouput will be saved locally"
)
}
Ok(())
Ok(self)
}

fn verify_added(&self) -> Result<(), Error> {
fn verify_added(&self) -> Result<&Self, Error> {
if self.mods.is_empty() {
return Err(Error::Missing(
"No mods registered, use the command 'add' to register a mod",
));
}
Ok(())
Ok(self)
}

fn verify_git(&self) -> Result<(), Error> {
fn verify_git(&self) -> Result<&Self, Error> {
if self.git_token.is_empty() {
return Err(Error::Missing(
"Git fine-grained token missing, Use command 'set' to store private token\n\
ouput will be saved locally",
));
}
Ok(())
Ok(self)
}

pub fn add_mod(mut self, details: Mod) -> Result<(), Error> {
Expand Down Expand Up @@ -187,23 +187,15 @@ async fn verify_gist() -> Result<(String, GistResponse), Error> {
}

async fn check_program_version() -> reqwest::Result<()> {
let client = reqwest::Client::new();
let version = client
.get(VERSION_URL)
.timeout(std::time::Duration::from_secs(4))
.send()
.await?
.json::<Version>()
.await?;
let version = reqwest::get(VERSION_URL).await?.json::<Version>().await?;
if version.latest != env!("CARGO_PKG_VERSION") {
println!("{}", version.message);
}
Ok(())
}

async fn update_download_counts(input: Input) -> Result<BTreeMap<u64, ModDetails>, Error> {
input.verify_nexus()?;
input.verify_added()?;
input.verify_nexus()?.verify_added()?;

let client = reqwest::Client::new();
let mut tasks = JoinSet::new();
Expand Down

0 comments on commit ac38971

Please sign in to comment.