mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-11 09:31:34 +11:00
Add the ability to read the dependencies of a crate
This commit is contained in:
parent
4277f07ec0
commit
c3f803206a
|
@ -20,6 +20,8 @@ pub enum Error {
|
||||||
PublishCrate,
|
PublishCrate,
|
||||||
Poll,
|
Poll,
|
||||||
CrateVersion,
|
CrateVersion,
|
||||||
|
ReadingDependencies,
|
||||||
|
CargoToml,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn command() -> clap::Command<'static> {
|
pub fn command() -> clap::Command<'static> {
|
||||||
|
@ -117,11 +119,7 @@ fn get_url_to_poll(crate_name: &str) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_cargo_toml_version(folder: &Path) -> Result<String, Error> {
|
fn read_cargo_toml_version(folder: &Path) -> Result<String, Error> {
|
||||||
let cargo_toml_contents =
|
let cargo_toml = read_cargo_toml(folder)?;
|
||||||
fs::read_to_string(folder.join("Cargo.toml")).map_err(|_| Error::CrateVersion)?;
|
|
||||||
let cargo_toml: Document = cargo_toml_contents
|
|
||||||
.parse()
|
|
||||||
.map_err(|_| Error::CrateVersion)?;
|
|
||||||
|
|
||||||
let version_value = cargo_toml["package"]["version"]
|
let version_value = cargo_toml["package"]["version"]
|
||||||
.as_value()
|
.as_value()
|
||||||
|
@ -132,6 +130,33 @@ fn read_cargo_toml_version(folder: &Path) -> Result<String, Error> {
|
||||||
Ok(version_value.to_owned())
|
Ok(version_value.to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_agb_dependencies(folder: &Path) -> Result<Vec<String>, Error> {
|
||||||
|
let cargo_toml = read_cargo_toml(folder)?;
|
||||||
|
|
||||||
|
let dependencies = cargo_toml["dependencies"]
|
||||||
|
.as_table()
|
||||||
|
.ok_or(Error::ReadingDependencies)?
|
||||||
|
.get_values();
|
||||||
|
|
||||||
|
let mut result = vec![];
|
||||||
|
|
||||||
|
for (key, _) in dependencies {
|
||||||
|
let dep = key[0].get();
|
||||||
|
if dep.starts_with("agb") {
|
||||||
|
result.push(dep.replace('_', "-"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_cargo_toml(folder: &Path) -> Result<Document, Error> {
|
||||||
|
let cargo_toml_contents =
|
||||||
|
fs::read_to_string(folder.join("Cargo.toml")).map_err(|_| Error::CargoToml)?;
|
||||||
|
let cargo_toml: Document = cargo_toml_contents.parse().map_err(|_| Error::CargoToml)?;
|
||||||
|
Ok(cargo_toml)
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -170,4 +195,21 @@ mod test {
|
||||||
assert_eq!(my_version, "0.1.0");
|
assert_eq!(my_version, "0.1.0");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn should_detect_dependencies() -> Result<(), Error> {
|
||||||
|
let root_directory = find_agb_root_directory()?;
|
||||||
|
let deps = get_agb_dependencies(&root_directory.join("agb"))?;
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
deps,
|
||||||
|
&[
|
||||||
|
"agb-image-converter",
|
||||||
|
"agb-sound-converter",
|
||||||
|
"agb-macros",
|
||||||
|
"agb-fixnum"
|
||||||
|
]
|
||||||
|
);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue