feat: output to csv file
This commit is contained in:
parent
d6bb8fa4b6
commit
fe9546fbff
5 changed files with 76 additions and 26 deletions
24
Cargo.lock
generated
24
Cargo.lock
generated
|
@ -148,13 +148,37 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"cargo_toml",
|
||||
"color-eyre",
|
||||
"csv",
|
||||
"forgejo-api",
|
||||
"futures",
|
||||
"semver",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tokio",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "csv"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac574ff4d437a7b5ad237ef331c17ccca63c46479e5b5453eb8e10bb99a759fe"
|
||||
dependencies = [
|
||||
"csv-core",
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "csv-core"
|
||||
version = "0.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5efa2b3d7902f4b634a20cae3c9c4e6209dc4779feb6863329607560143efa70"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "deranged"
|
||||
version = "0.3.11"
|
||||
|
|
|
@ -7,8 +7,11 @@ edition = "2021"
|
|||
[dependencies]
|
||||
cargo_toml = "0.20.4"
|
||||
color-eyre = "0.6.3"
|
||||
csv = "1.3.0"
|
||||
forgejo-api = "0.4.1"
|
||||
futures = "0.3.30"
|
||||
semver = "1.0.23"
|
||||
serde = { version = "1.0.210", features = ["derive"] }
|
||||
serde_json = "1.0.128"
|
||||
tokio = { version = "1.40.0", features = ["full"] }
|
||||
url = "2.5.2"
|
||||
|
|
10
dependencies.csv
Normal file
10
dependencies.csv
Normal file
|
@ -0,0 +1,10 @@
|
|||
name,version,source
|
||||
color-eyre,0.6.3,0
|
||||
tracing,0.1.40,0
|
||||
tracing-subscriber,0.3.18,0
|
||||
cargo_toml,0.20.4,0
|
||||
forgejo-api,0.4.1,0
|
||||
futures,0.3.30,0
|
||||
semver,1.0.23,0
|
||||
tokio,1.40.0,0
|
||||
url,2.5.2,0
|
|
24
src/dependency.rs
Normal file
24
src/dependency.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
use serde::Serialize;
|
||||
use std::borrow::Cow;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[repr(i8)]
|
||||
pub enum DependencySource {
|
||||
Crates = 0,
|
||||
}
|
||||
|
||||
impl Serialize for DependencySource {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
serializer.serialize_i8(*self as i8)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct Dependency {
|
||||
pub name: Cow<'static, str>,
|
||||
pub version: Cow<'static, str>,
|
||||
pub source: DependencySource,
|
||||
}
|
41
src/main.rs
41
src/main.rs
|
@ -1,34 +1,18 @@
|
|||
mod dependency;
|
||||
|
||||
use cargo_toml::{Dependency as Crate, Manifest};
|
||||
use color_eyre::{eyre::eyre, Result};
|
||||
use csv::Writer;
|
||||
use dependency::{Dependency, DependencySource};
|
||||
use forgejo_api::{
|
||||
structs::{OrgListReposQuery, RepoGetRawFileQuery},
|
||||
Forgejo,
|
||||
};
|
||||
use futures::future::join_all;
|
||||
use semver::Version;
|
||||
use std::{borrow::Cow, env};
|
||||
use std::env;
|
||||
use url::Url;
|
||||
|
||||
#[derive(Debug)]
|
||||
enum DependencySource {
|
||||
Crates,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Dependency {
|
||||
name: Cow<'static, str>,
|
||||
version: Version,
|
||||
source: DependencySource,
|
||||
}
|
||||
|
||||
impl Dependency {
|
||||
pub fn get_url(&self) -> String {
|
||||
match self.source {
|
||||
DependencySource::Crates => format!("https://crates.io/crates/{}", self.name),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
color_eyre::install()?;
|
||||
|
@ -96,15 +80,20 @@ async fn main() -> Result<()> {
|
|||
.iter()
|
||||
.map(|(name, version)| Dependency {
|
||||
name: name.clone().into(),
|
||||
version: version.clone(),
|
||||
version: version.to_string().into(),
|
||||
source: DependencySource::Crates,
|
||||
})
|
||||
.collect();
|
||||
|
||||
println!(
|
||||
"{:?}",
|
||||
crates.iter().map(|c| c.get_url()).collect::<Vec<_>>()
|
||||
);
|
||||
// write the dependencies to a file
|
||||
let mut dependencies = vec![];
|
||||
dependencies.extend(crates);
|
||||
let file = std::fs::File::create("dependencies.csv")?;
|
||||
let mut wtr = Writer::from_writer(file);
|
||||
for dependency in dependencies {
|
||||
wtr.serialize(dependency)?;
|
||||
}
|
||||
wtr.flush()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue