Skip to content

Commit

Permalink
rely on os-checker-plugin v0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
zjp-CN committed Nov 23, 2024
1 parent 0c2c5e9 commit 804a475
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 38 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A plugin to os-checker to collect basic information from cargo and git.
repository = "https://github.com/os-checker/plugin-cargo"

[dependencies]
plugin = { version = "0.1.1", package = "os-checker-plugin" }
plugin = { version = "0.1.2", package = "os-checker-plugin" }
os-checker-types = "0.4.1"

serde = "1"
Expand Down
31 changes: 0 additions & 31 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,9 @@ extern crate eyre;
#[macro_use]
extern crate tracing;

use plugin::prelude::*;

pub mod crates_io;
pub mod database;
pub mod nextest;
pub mod repo;

pub const BASE: &str = "tmp";

use std::fs;

pub fn write_json<T: serde::Serialize>(path: &Utf8Path, val: &T) -> Result<()> {
let _span = error_span!("write_json", ?path).entered();
fs::create_dir_all(path.parent().unwrap())?;
serde_json::to_writer_pretty(fs::File::create(path)?, val)?;
Ok(())
}

/// Get the list of repos, searching in the following order:
/// * the first argument: a json path to a vec of repo string
/// * or read from the result of `os-checker config --list-repos`
pub fn repos() -> Result<Vec<String>> {
let arg = std::env::args().nth(1);

let text = match arg.as_deref() {
Some(list_json) => {
let path = Utf8Path::new(list_json);
fs::read_to_string(path)?
}
None => duct::cmd!("os-checker", "config", "--list-repos")
.env_remove("RUST_LOG")
.read()?,
};

info!(text);
Ok(serde_json::from_str(&text)?)
}
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use os_checker_plugin_cargo::{repo, repos, write_json, BASE};
use plugin::{logger, prelude::*};
use os_checker_plugin_cargo::{repo, BASE};
use plugin::{logger, prelude::*, repos, write_json};

#[macro_use]
extern crate tracing;
Expand Down
4 changes: 2 additions & 2 deletions src/repo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{crates_io::IndexFile, database::diag_total_count};
use cargo_metadata::Package;
use eyre::ContextCompat;
use output::Output;
use plugin::prelude::*;
use plugin::{prelude::*, write_json};
use std::sync::LazyLock;
use testcases::PkgTests;

Expand Down Expand Up @@ -130,7 +130,7 @@ impl Repo {
fn write_json(&self, json: &serde_json::Value) -> Result<()> {
let mut path = Utf8PathBuf::from_iter([crate::BASE, &self.user, &self.repo]);
path.set_extension("json");
crate::write_json(&path, json)
write_json(&path, json)
}

pub fn remove_local_dir(self) -> Result<()> {
Expand Down

0 comments on commit 804a475

Please sign in to comment.