added basic cli
This commit is contained in:
20
src/cli.rs
Normal file
20
src/cli.rs
Normal 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 },
|
||||
}
|
||||
86
src/main.rs
86
src/main.rs
@@ -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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user