|
|
|
@ -17,6 +17,7 @@ pub struct Project {
|
|
|
|
|
path: PathBuf,
|
|
|
|
|
name: String,
|
|
|
|
|
msrv: Option<Version>,
|
|
|
|
|
crate_version: Version,
|
|
|
|
|
pub repo: Box<dyn Repository>,
|
|
|
|
|
profile_map: HashMap<String, String>, // vcs profile name to branch names
|
|
|
|
|
}
|
|
|
|
@ -48,12 +49,17 @@ impl Project {
|
|
|
|
|
.to_owned();
|
|
|
|
|
|
|
|
|
|
let repo = GitRepository::open(&path)?;
|
|
|
|
|
let msrv = Self::parse_msrv(&path)?;
|
|
|
|
|
let msrv = Self::parse_version(&path, "rust-version")?;
|
|
|
|
|
let crate_version = match Self::parse_version(&path, "version")? {
|
|
|
|
|
Some(v) => v,
|
|
|
|
|
None => return Err(Error::cargo_error("Crate version not found")),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Ok(Self {
|
|
|
|
|
path,
|
|
|
|
|
name,
|
|
|
|
|
msrv,
|
|
|
|
|
crate_version,
|
|
|
|
|
repo,
|
|
|
|
|
profile_map,
|
|
|
|
|
})
|
|
|
|
@ -108,18 +114,18 @@ impl Project {
|
|
|
|
|
self.msrv.as_ref()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn parse_msrv(path: &Path) -> Result<Option<Version>, Error> {
|
|
|
|
|
fn parse_version(path: &Path, key: &str) -> Result<Option<Version>, Error> {
|
|
|
|
|
let toml_path = path.join("Cargo.toml");
|
|
|
|
|
let toml_contents = std::fs::read_to_string(toml_path)?;
|
|
|
|
|
|
|
|
|
|
let cargo: toml::Value = toml::from_str(&toml_contents)?;
|
|
|
|
|
|
|
|
|
|
if let Some(pkg) = cargo.get("package") {
|
|
|
|
|
if let Some(value) = pkg.get("rust-version") {
|
|
|
|
|
if let Some(value) = pkg.get(key) {
|
|
|
|
|
if value.is_str() {
|
|
|
|
|
let mut ver_str = value
|
|
|
|
|
.as_str()
|
|
|
|
|
.ok_or_else(|| Error::cargo_error("Unparsable rust-version in Cargo.toml"))?
|
|
|
|
|
.ok_or_else(|| Error::cargo_error("Unparsable version in Cargo.toml"))?
|
|
|
|
|
.to_owned();
|
|
|
|
|
let dots = ver_str.chars().filter(|c| *c == '.').count();
|
|
|
|
|
if !(1..=2).contains(&dots) {
|
|
|
|
@ -141,8 +147,9 @@ impl Project {
|
|
|
|
|
|
|
|
|
|
pub fn display(&self, options: EnumSet<ProjectDisplayOptions>) -> Result<Tree<String>, Error> {
|
|
|
|
|
let title = format!(
|
|
|
|
|
"{}: {} [{}]",
|
|
|
|
|
"{}@{}: {} [{}]",
|
|
|
|
|
self.name().bold().with(PROJECT_COLOR),
|
|
|
|
|
format!("v{}", self.crate_version).with(VERSION_COLOR),
|
|
|
|
|
self.current_ref()?
|
|
|
|
|
.unwrap_or_else(|| "???".into())
|
|
|
|
|
.with(REFS_COLOR),
|
|
|
|
|