z_mirror/fmm

git clone https://git.raiguard.me/z_mirror/fmm

raiguardBroken half-implementation of dependencies7007399

dependencies
2.3 KiB88 linesraw
1mod dependency;
2mod input;
3mod mods_set;
4
5use std::collections::HashSet;
6use std::error::Error;
7use std::path::PathBuf;
8use structopt::StructOpt;
9
10use crate::input::InputMod;
11use crate::mods_set::ModsSet;
12
13// TODO: Figure out why it's not coloring the help info.
14#[derive(Debug, StructOpt)]
15#[structopt(
16    name = "fmm",
17    about = "Enable, disable, download, update, create, and delete Factorio mods."
18)]
19struct App {
20    /// Deduplicate zipped mod versions, leaving only the latest version
21    #[structopt(long)]
22    dedup: bool,
23    /// The path to the mods directory
24    // TODO: Make optional, introduce config file to specify default path
25    #[structopt(short = "f", long)]
26    dir: PathBuf,
27    /// Disable all mods.
28    #[structopt(short = "o", long)]
29    disable_all: bool,
30    /// A list of mods to disable. Format is `mod_name` or `mod_name@version`.
31    #[structopt(short, long)]
32    disable: Vec<InputMod>,
33    /// Enable the latest versions of all mods.
34    #[structopt(short = "l", long)]
35    enable_all: bool,
36    /// A list of mods to enable. Enabling a mod will enable all of its dependencies as well.
37    /// Format is `mod_name` or `mod_name@version`.
38    #[structopt(short, long)]
39    enable: Vec<InputMod>,
40    /// Ignore mod dependencies when enabling them.
41    #[structopt(long)]
42    ignore_dependencies: bool,
43    /// Include the base mod when calling `disable-all`.
44    #[structopt(long)]
45    include_base_mod: bool,
46    /// A list of mods to remove. If no version is provided, the latest version will be removed.
47    #[structopt(short, long)]
48    remove: Vec<InputMod>,
49}
50
51fn main() -> Result<(), Box<dyn Error>> {
52    let app = App::from_args();
53
54    let mut set = ModsSet::new(&app.dir)?;
55
56    for mod_ident in app.remove.iter() {
57        set.remove(mod_ident)?;
58    }
59
60    if app.dedup {
61        set.dedup()?;
62    }
63
64    if app.disable_all {
65        set.disable_all(app.include_base_mod);
66    }
67
68    if app.enable_all {
69        set.enable_all();
70    }
71
72    for mod_ident in app.disable.iter() {
73        set.disable(mod_ident)?;
74    }
75
76    if app.enable.len() > 0 {
77        let enabled_names: HashSet<String> = HashSet::new();
78        let to_enable = app.enable.clone();
79
80        for mod_ident in to_enable.iter() {
81            set.enable(mod_ident)?;
82        }
83    }
84
85    set.write_mod_list()?;
86
87    Ok(())
88}