Skip to content

Commit

Permalink
source resolution works
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAlan404 committed Jun 13, 2024
1 parent 8ba0145 commit b2d35e0
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/api/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use reqwest::{IntoUrl, Response};
use serde::de::DeserializeOwned;
use tokio::{sync::RwLock, time::sleep};

use super::{models::{network::{Network, NETWORK_TOML}, server::{Server, SERVER_TOML}, Addon}, utils::{try_find_toml_upwards, write_toml}};
use super::{models::{network::{Network, NETWORK_TOML}, server::{Server, SERVER_TOML}, Addon, Source}, utils::{try_find_toml_upwards, write_toml}};

pub mod actions;
pub mod cache;
Expand Down Expand Up @@ -109,15 +109,23 @@ impl App {
Ok(res.json().await?)
}

pub async fn collect_addons(&self) -> Result<Vec<Addon>> {
let mut addons = vec![];
pub async fn collect_sources(&self) -> Result<Vec<Source>> {
let mut sources = vec![];

if let Some(lock) = &self.server {
let server = lock.read().await;

for source in &server.sources {
addons.append(&mut source.resolve_addons(&self).await?);
}
sources.append(&mut server.sources.clone());
}

Ok(sources)
}

pub async fn collect_addons(&self) -> Result<Vec<Addon>> {
let mut addons = vec![];

for source in self.collect_sources().await? {
addons.append(&mut source.resolve_addons(&self).await?);

Check failure on line 128 in src/api/app/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

error: this expression creates a reference which is immediately dereferenced by the compiler --> src/api/app/mod.rs:128:54 | 128 | addons.append(&mut source.resolve_addons(&self).await?); | ^^^^^ help: change this to: `self` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
}

Ok(addons)
Expand Down
1 change: 1 addition & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod init;
pub mod build;
pub mod sources;
16 changes: 16 additions & 0 deletions src/commands/sources/list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use anyhow::Result;

use crate::api::app::App;

#[derive(clap::Args)]
pub struct Args {

}

pub async fn run(mut app: App, args: Args) -> Result<()> {

Check warning on line 10 in src/commands/sources/list.rs

View workflow job for this annotation

GitHub Actions / clippy

variable does not need to be mutable

warning: variable does not need to be mutable --> src/commands/sources/list.rs:10:18 | 10 | pub async fn run(mut app: App, args: Args) -> Result<()> { | ----^^^ | | | help: remove this `mut`

Check warning on line 10 in src/commands/sources/list.rs

View workflow job for this annotation

GitHub Actions / clippy

unused variable: `args`

warning: unused variable: `args` --> src/commands/sources/list.rs:10:32 | 10 | pub async fn run(mut app: App, args: Args) -> Result<()> { | ^^^^ help: if this is intentional, prefix it with an underscore: `_args`
let sources = app.collect_sources().await?;

println!("{sources:#?}");

Ok(())
}
16 changes: 16 additions & 0 deletions src/commands/sources/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use anyhow::Result;

use crate::api::app::App;

pub mod list;

#[derive(clap::Subcommand)]
pub enum Commands {
List(list::Args),
}

pub async fn run(mut app: App, args: Commands) -> Result<()> {

Check warning on line 12 in src/commands/sources/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

variable does not need to be mutable

warning: variable does not need to be mutable --> src/commands/sources/mod.rs:12:18 | 12 | pub async fn run(mut app: App, args: Commands) -> Result<()> { | ----^^^ | | | help: remove this `mut`
match args {
Commands::List(args) => list::run(app, args).await,
}
}
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ struct Cli {
#[derive(clap::Subcommand)]
enum Commands {
Init(commands::init::Args),
#[command(subcommand)]
Sources(commands::sources::Commands),
}

#[tokio::main]
Expand All @@ -28,5 +30,6 @@ async fn main() -> Result<()> {

match args.command {
Commands::Init(args) => commands::init::run(app, args).await,
Commands::Sources(args) => commands::sources::run(app, args).await,
}
}

0 comments on commit b2d35e0

Please sign in to comment.