feat: separated lib and cli behind features

This commit is contained in:
əlemi 2023-10-20 04:20:53 +02:00
parent 86dbf15f01
commit ac20d43b20
Signed by: alemi
GPG key ID: A4895B84D311642C
4 changed files with 42 additions and 21 deletions

View file

@ -7,22 +7,38 @@ repository = "https://github.com/alemidev/fedicharter"
readme = "README.md" readme = "README.md"
edition = "2021" edition = "2021"
[lib]
name = "fedicharter"
path = "src/lib.rs"
[[bin]]
name = "fedicharter-cli"
path = "src/cli/main.rs"
required-features = ["cli"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
async-recursion = "1.0.5" async-recursion = "1.0.5"
axum = "0.6.20"
chrono = "0.4.31" chrono = "0.4.31"
clap = { version = "4.4.6", features = ["derive"] } thiserror = "1.0.49"
derive_more = "0.99.17" derive_more = "0.99.17"
lazy_static = "1.4.0"
# nodeinfo = { git = "https://codeberg.org/thefederationinfo/nodeinfo-rs.git" }
reqwest = { version = "0.11.20", features = ["json"] }
sea-orm = { version = "0.12.3", features = ["runtime-tokio-native-tls", "sqlx-sqlite", "sqlx-postgres"] }
serde = { version = "1.0.188", features = ["derive"] } serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.107" serde_json = "1.0.107"
thiserror = "1.0.49" tracing = "0.1.37" # TODO either this or log
tokio = { version = "1.32.0", features = ["full"] } log = "0.4.20" # TODO either this or tracing
tracing = "0.1.37" #nodeinfo = { git = "https://codeberg.org/thefederationinfo/nodeinfo-rs.git" }
tracing-subscriber = "0.3.17"
# async runtime and cli stuff
tokio = { version = "1.32.0", features = ["full"], optional = true }
tracing-subscriber = { version = "0.3.17", optional = true }
axum = { version = "0.6.20", optional = true }
reqwest = { version = "0.11.20", features = ["json"], optional = true }
sea-orm = { version = "0.12.3", features = ["runtime-tokio-native-tls", "sqlx-sqlite", "sqlx-postgres"], optional = true }
clap = { version = "4.4.6", features = ["derive"], optional = true }
[features]
default = ["web", "cli"]
db = ["dep:tokio", "dep:sea-orm", "dep:reqwest"]
cli = ["db", "dep:axum", "dep:tracing-subscriber", "dep:clap"]

View file

@ -1,19 +1,11 @@
use std::net::SocketAddr; use std::net::SocketAddr;
use crawl::collector::CollectorHandle; use fedicharter::crawl::collector::CollectorHandle;
use sea_orm::Database; use sea_orm::Database;
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
use tracing_subscriber::{prelude::*, filter::{LevelFilter, filter_fn}}; use tracing_subscriber::{prelude::*, filter::{LevelFilter, filter_fn}};
mod nodeinfo; // TODO this should me PRd into upstream
mod entities;
mod crawl;
mod serve;
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
/// an API crawling akkoma bubble instances network and creating a map /// an API crawling akkoma bubble instances network and creating a map
struct CliArgs { struct CliArgs {
@ -79,12 +71,12 @@ async fn main() {
Some(host) => host.parse().expect("could not parse provided host"), Some(host) => host.parse().expect("could not parse provided host"),
None => SocketAddr::from(([127, 0, 0, 1], 18811)), None => SocketAddr::from(([127, 0, 0, 1], 18811)),
}; };
crate::serve::api_routes(addr, db).await; fedicharter::serve::api_routes(addr, db).await;
}, },
CliAction::Crawl { mode: CliCrawlMode::Bubble { domain } } => { CliAction::Crawl { mode: CliCrawlMode::Bubble { domain } } => {
let collector = CollectorHandle::new(db).await; let collector = CollectorHandle::new(db).await;
crate::crawl::bubble(&domain, collector).await.expect("network error wtf"); fedicharter::crawl::bubble(&domain, collector).await.expect("network error wtf");
}, },
} }
} }

10
src/lib.rs Normal file
View file

@ -0,0 +1,10 @@
pub mod nodeinfo; // TODO this should me PRd into upstream
#[cfg(feature = "db")]
pub mod entities;
#[cfg(feature = "cli")]
pub mod crawl;
#[cfg(feature = "cli")]
pub mod serve;

View file

@ -1,4 +1,7 @@
pub mod model; pub mod model;
#[cfg(feature = "cli")]
pub mod fetcher; pub mod fetcher;
#[cfg(feature = "cli")]
pub use fetcher::fetch_node_info as fetch; pub use fetcher::fetch_node_info as fetch;