use crate::builder::ProfileType;
use jam_program_blob::CrateInfo;
use std::{path::Path, process::Command};
#[derive(clap::ValueEnum, Clone, Debug, Default)]
#[value(rename_all = "lowercase")]
pub enum ModuleType {
#[clap(alias = "auto")]
#[default]
Automatic,
#[clap(alias = "serv")]
Service,
#[clap(alias = "auth")]
Authorizer,
#[clap(alias = "guest")]
CoreVmGuest,
}
#[derive(clap::ValueEnum, Clone, Debug, Default)]
#[value(rename_all = "lowercase")]
pub enum Profile {
Debug,
#[default]
Release,
Production,
}
impl From<Profile> for ProfileType {
fn from(profile: Profile) -> ProfileType {
match profile {
Profile::Debug => ProfileType::Debug,
Profile::Release => ProfileType::Release,
Profile::Production => ProfileType::Other("production"),
}
}
}
pub fn crate_info(krate: &Path) -> anyhow::Result<CrateInfo> {
let man = serde_json::from_str::<serde_json::Value>(&String::from_utf8(
Command::new("cargo")
.arg("read-manifest")
.current_dir(krate)
.output()?
.stdout,
)?)?;
let name = man
.get("name")
.expect("could not find package name in Cargo.toml")
.as_str()
.expect("package name is not a string")
.to_string();
let version = man
.get("version")
.expect("could not find package version in Cargo.toml")
.as_str()
.expect("package version is not a string")
.to_string();
let license = man
.get("license")
.expect("could not find package license in Cargo.toml")
.as_str()
.expect("package license is not a string")
.to_string();
let authors = man
.get("authors")
.expect("could not find authors in Cargo.toml")
.as_array()
.expect("authors is not an array")
.iter()
.map(|x| x.as_str().expect("author is not a string").to_owned())
.collect::<Vec<String>>();
Ok(CrateInfo {
name,
version,
license,
authors,
})
}