added basic cli

This commit is contained in:
2026-03-02 21:03:27 +01:00
parent 0a3b1cc9ed
commit 217d2303a6
4 changed files with 218 additions and 16 deletions

127
Cargo.lock generated
View File

@@ -17,6 +17,56 @@ version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
[[package]]
name = "anstream"
version = "0.6.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78"
[[package]]
name = "anstyle-parse"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
dependencies = [
"anstyle",
"once_cell_polyfill",
"windows-sys",
]
[[package]]
name = "arraydeque"
version = "0.5.1"
@@ -35,6 +85,52 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "clap"
version = "4.5.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2797f34da339ce31042b27d23607e051786132987f595b02ba4f6a6dffb7030a"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.5.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24a241312cea5059b13574bb9b3861cabf758b879c15190b37b6d6fd63ab6876"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.5.55"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a92793da1a46a5f2a02a6f4c46c6496b28c43638adea8306fcb0caa1634f24e5"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a822ea5bc7590f9d40f1ba12c0dc3c2760f3482c6984db1573ad11031420831"
[[package]]
name = "colorchoice"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
[[package]]
name = "const-random"
version = "0.1.18"
@@ -180,6 +276,7 @@ checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb"
name = "fomod-manager"
version = "0.1.0"
dependencies = [
"clap",
"libloot",
"quick-xml",
"serde",
@@ -232,6 +329,12 @@ dependencies = [
"hashbrown 0.15.5",
]
[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
name = "indexmap"
version = "2.13.0"
@@ -242,6 +345,12 @@ dependencies = [
"hashbrown 0.16.1",
]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
[[package]]
name = "keyvalues-parser"
version = "0.2.3"
@@ -352,6 +461,12 @@ version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "once_cell_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
[[package]]
name = "option-ext"
version = "0.2.0"
@@ -576,6 +691,12 @@ dependencies = [
"serde_core",
]
[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "syn"
version = "2.0.117"
@@ -673,6 +794,12 @@ version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "wasi"
version = "0.11.1+wasi-snapshot-preview1"

View File

@@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2024"
[dependencies]
clap = { version = "4.5.60", features = ["derive"] }
libloot = "0.29.0"
quick-xml = { version = "0.39.2", features = ["serde-types", "serialize"] }
serde = { version = "1.0.228", features = ["derive"] }

20
src/cli.rs Normal file
View File

@@ -0,0 +1,20 @@
use std::path::PathBuf;
use clap::{Parser, Subcommand};
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
pub struct Args {
#[arg(short, long, value_name = "FILE")]
pub config: PathBuf,
#[command(subcommand)]
pub command: Commands,
}
#[derive(Subcommand, Debug)]
pub enum Commands {
Activate { instance: String, target: PathBuf },
Add { instance: String, mod_id: String },
LoadOrder { instance: String },
}

View File

@@ -1,14 +1,18 @@
use std::{error::Error, path::Path};
use clap::Parser;
use crate::{
basic_types::{ModConfig, ModFile, ModdedInstance, RootConfig},
cli::Args,
fomod::Config,
linker::{link_game_to_target, link_instance_to_target},
linker::{create_plugins_txt, link_game_to_target, link_instance_to_target},
load_order::LoadOrder,
mod_config_installer::FomodInstaller,
};
mod basic_types;
mod cli;
mod conflict_resolver;
mod fomod;
mod install_prompt;
@@ -44,22 +48,43 @@ pub fn gen_filelist_for_mod(
Ok(converted_files)
}
fn main() -> Result<(), Box<dyn Error>> {
let root_config = RootConfig::load_from_file("./data/example.toml")?;
pub fn activate_instance(
root_config: &RootConfig,
instance_id: &str,
target: &Path,
) -> Result<(), Box<dyn Error>> {
let instance_config = root_config.load_instance_by_id(instance_id)?;
// let mut new_instance = ModdedInstance::new("My Instance");
// let mod_to_install = root_config.get_mod_by_id("ineed").unwrap();
// let new_files = gen_filelist_for_mod(&root_config, &new_instance, &mod_to_install)?;
// new_instance.add_mod(&mod_to_install, 0, &new_files);
// new_instance.save_to_file("./data/my_instance.toml")?;
link_game_to_target(&root_config.games.first().unwrap().install_location, target)?;
link_instance_to_target(root_config, &instance_config, target)?;
create_plugins_txt(&instance_config, target)?;
let modded_instance = ModdedInstance::load_from_file("./data/my_instance.toml")?;
Ok(())
}
link_game_to_target(
&root_config.games.first().unwrap().install_location,
"./data/target",
)?;
link_instance_to_target(&root_config, &modded_instance, "./data/target")?;
pub fn add_mod_to_instance(
root_config: &RootConfig,
instance_id: &str,
mod_id: &str,
) -> Result<(), Box<dyn Error>> {
let mut instance_config = root_config.load_instance_by_id(instance_id)?.clone();
let mod_config = root_config.get_mod_by_id(mod_id).ok_or("Mod not found")?;
let new_files = gen_filelist_for_mod(root_config, &instance_config, &mod_config)?;
instance_config.add_mod(&mod_config, 0, &new_files);
let path = &root_config
.get_instance_config(instance_id)
.ok_or("Mod not found")?
.path;
instance_config.save_to_file(path)?;
Ok(())
}
pub fn order_plugins(root_config: &RootConfig, instance_id: &str) -> Result<(), Box<dyn Error>> {
let mut instance_config = root_config.load_instance_by_id(instance_id)?.clone();
let mut orderer = LoadOrder::new(
&root_config.games.first().unwrap().install_location,
@@ -67,9 +92,38 @@ fn main() -> Result<(), Box<dyn Error>> {
)?;
orderer.add_plugins_from_install()?;
orderer.add_plugins_from_instance(&root_config, &modded_instance)?;
orderer.add_plugins_from_instance(root_config, &instance_config)?;
orderer.load_order()?;
let load_order = orderer.load_order()?;
instance_config.set_load_order(load_order);
let path = &root_config
.get_instance_config(instance_id)
.ok_or("Mod not found")?
.path;
instance_config.save_to_file(path)?;
Ok(())
}
fn main() -> Result<(), Box<dyn Error>> {
let args = Args::parse();
let root_config = RootConfig::load_from_file(args.config)?;
match args.command {
cli::Commands::Activate { instance, target } => {
activate_instance(&root_config, &instance, &target)?;
}
cli::Commands::Add { instance, mod_id } => {
add_mod_to_instance(&root_config, &instance, &mod_id)?;
}
cli::Commands::LoadOrder { instance } => {
order_plugins(&root_config, &instance)?;
}
}
Ok(())
}