Initial draft of profile metadata format & CLI (#17)

* Initial draft of profile metadata format

* Remove records, add Clippy to Nix, fix Clippy error

* Work on profile definition

* BREAKING: Make global settings consistent with profile settings

* Add builder methods & format

* Integrate launching with profiles

* Add profile loading

* Launching via profile, API tweaks, and yak shaving

* Incremental update, committing everything due to personal system maintainance

* Prepare for review cycle

* Remove reminents of experimental work

* CLI: allow people to override the non-empty directory check

* Fix mistake in previous commit

* Handle trailing whitespace and newlines in prompts

* Revamp prompt to use dialoguer and support defaults

* Make requested changes
This commit is contained in:
Danielle
2022-03-28 18:41:35 -07:00
committed by GitHub
parent 98aa66f9d8
commit d1070ca213
27 changed files with 1825 additions and 334 deletions

View File

@@ -22,10 +22,12 @@ pub const COMPILED_ZIP: &str = "compiled.mrpack";
pub const MANIFEST_PATH: &str = "modrinth.index.json";
pub const OVERRIDES_PATH: &str = "overrides/";
pub const PACK_JSON5_PATH: &str = "modpack.json5";
const PACK_GITIGNORE: &'static str = const_format::formatcp!(r#"
const PACK_GITIGNORE: &'static str = const_format::formatcp!(
r#"
{COMPILED_PATH}
{COMPILED_ZIP}
"#);
"#
);
#[derive(thiserror::Error, Debug)]
pub enum ModpackError {

View File

@@ -21,7 +21,10 @@ pub trait ModrinthAPI {
channel: &str,
game: &ModpackGame,
) -> ModpackResult<HashSet<ModpackFile>>;
async fn get_version(&self, version: &str) -> ModpackResult<HashSet<ModpackFile>>;
async fn get_version(
&self,
version: &str,
) -> ModpackResult<HashSet<ModpackFile>>;
}
#[derive(Debug)]
@@ -93,6 +96,8 @@ impl ModrinthAPI for ModrinthV1 {
String::from("Modrinth V1 does not support vanilla projects"),
)),
ModpackGame::Minecraft(ref version, ref loader) => Ok((version, loader)),
// This guard is here for when Modrinth does support other games.
#[allow(unreachable_patterns)]
_ => Err(ModpackError::VersionError(String::from(
"Attempted to use Modrinth API V1 to install a non-Minecraft project!",
))),
@@ -131,7 +136,8 @@ impl ModrinthAPI for ModrinthV1 {
.map(ModpackFile::from)
.collect::<HashSet<ModpackFile>>();
let dep_futures = version.dependencies.iter().map(|it| self.get_version(it));
let dep_futures =
version.dependencies.iter().map(|it| self.get_version(it));
let deps = try_join_all(dep_futures)
.await?
.into_iter()
@@ -148,12 +154,17 @@ impl ModrinthAPI for ModrinthV1 {
.collect())
}
async fn get_version(&self, version: &str) -> ModpackResult<HashSet<ModpackFile>> {
async fn get_version(
&self,
version: &str,
) -> ModpackResult<HashSet<ModpackFile>> {
let domain = &self.0;
let version_json = try_get_json(format!("{domain}/api/v1/version/{version}")).await?;
let mut version_deserializer = serde_json::Deserializer::from_slice(&version_json);
let version = ModrinthV1ProjectVersion::deserialize(&mut version_deserializer)?;
let base_path = PathBuf::from("mods/");
let version_json =
try_get_json(format!("{domain}/api/v1/version/{version}")).await?;
let mut version_deserializer =
serde_json::Deserializer::from_slice(&version_json);
let version =
ModrinthV1ProjectVersion::deserialize(&mut version_deserializer)?;
Ok(version
.files

View File

@@ -159,6 +159,7 @@ pub struct ModpackFile {
pub downloads: HashSet<String>,
}
#[allow(clippy::derive_hash_xor_eq)]
impl Hash for ModpackFile {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
if let Some(ref hashes) = self.hashes {