Skip to content

Commit

Permalink
feat(config): Add config parser file for mod installer
Browse files Browse the repository at this point in the history
Signed-off-by: dark0dave <[email protected]>
  • Loading branch information
dark0dave committed Aug 25, 2024
1 parent d77b917 commit 8768d42
Show file tree
Hide file tree
Showing 9 changed files with 394 additions and 158 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
.swp
target/
dist/
Cargo.toml.test
164 changes: 163 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mod_installer"
version = "8.1.0"
version = "9.0.0"
edition = "2021"
authors = [ "dark0dave" ]
documentation = "https://raw.githubusercontent.com/dark0dave/mod_installer/main/README.md"
Expand All @@ -19,14 +19,14 @@ keywords = [
]

[dependencies]
confy = "^0.5"
clap = { version = "4.5.9", features = ["derive", "env"] }
env_logger = "0.11.1"
fs_extra = "1.3.0"
log = "0.4.22"
serde = { version = "1.0.152", features = ["derive"] }
serde_derive = "1.0.152"
walkdir = "2.3.2"

[dependencies.clap]
version = "4.5.9"
features = [ "derive", "env" ]

[dev-dependencies]
pretty_assertions = "1.3.0"
30 changes: 21 additions & 9 deletions check-version.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
#!/usr/bin/env bash
set -euo pipefail

release_tag=$(git describe --tags --abbrev=0);
trap "rm -f Cargo.toml.test" SIGINT;
sed "s/^version \= .*/version = \"${release_tag/v/}\"/" Cargo.toml > Cargo.toml.test;
diff -sd Cargo.toml.test Cargo.toml;
if [ $? -eq 0 ]; then
rm -f Cargo.toml.test;
exit 0;
else
function version_gt() { test "$(echo "$@" | tr " " "\n" | sort -V | head -n 1)" != "$1"; }

function main() {
local tag_version=$(git describe --tags --abbrev=0);
echo "Git tag version: ${tag_version}"
local current_version=$(head -3 Cargo.toml | tail -1 | sed -E "s/^version \= \"(.*)\"/\1/")
echo "Cargo.toml version: v${current_version}"
if [ "${tag_version}" == "v${current_version}" ]; then
echo "Versions are the same"
exit 0;
fi

if version_gt "v${current_version}" "${tag_version}"; then
echo "Current version greater than tag version"
exit 0;
fi

echo "Failed, tag version: ${tag_version} is greater than Cargo,toml: v${current_version}"
exit 1;
fi
}

main
4 changes: 3 additions & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use std::path::PathBuf;

use clap::{ArgAction, Parser};

const WEIDU_LOG_MODE_ERROR: &str = r"
pub(crate) const CARGO_PKG_NAME: &str = env!("CARGO_PKG_NAME");

pub(crate) const WEIDU_LOG_MODE_ERROR: &str = r"
Please provide a valid weidu logging setting, options are:
--weidu-log-mode log X log output and details to X
--weidu-log-mode autolog log output and details to WSETUP.DEBUG
Expand Down
15 changes: 13 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::{collections::HashMap, process::ExitCode};
use std::{collections::HashMap, process::ExitCode, sync::Arc};

use args::Args;
use args::{Args, CARGO_PKG_NAME};
use clap::Parser;
use env_logger::Env;
use parser_config::ParserConfig;
use utils::find_mods;

use crate::{
Expand All @@ -13,6 +14,7 @@ use crate::{
mod args;
mod component;
mod log_file;
mod parser_config;
mod state;
mod utils;
mod weidu;
Expand Down Expand Up @@ -43,6 +45,14 @@ fn main() -> ExitCode {
}
};

let parser_config: Arc<ParserConfig> = match confy::load(CARGO_PKG_NAME, None) {
Ok(config) => Arc::new(config),
Err(err) => {
log::error!("Internal error with config crate, {:?}", err);
return ExitCode::FAILURE;
}
};

let mut mod_folder_cache = HashMap::new();
for weidu_mod in &mods_to_be_installed {
let mod_folder = mod_folder_cache
Expand All @@ -63,6 +73,7 @@ fn main() -> ExitCode {
match install(
&args.weidu_binary,
&args.game_directory,
parser_config.clone(),
weidu_mod,
&args.language,
&args.weidu_log_mode,
Expand Down
Loading

0 comments on commit 8768d42

Please sign in to comment.