z_mirror/fmm
git clone https://git.raiguard.me/z_mirror/fmm
7007399
dependencies
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 ( 16name = "fmm" , 17about = "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 )] 22dedup : bool , 23/// The path to the mods directory 24// TODO: Make optional, introduce config file to specify default path 25# [ structopt ( short = "f" , long )] 26dir : PathBuf , 27/// Disable all mods. 28# [ structopt ( short = "o" , long )] 29disable_all : bool , 30/// A list of mods to disable. Format is `mod_name` or `mod_name@version`. 31# [ structopt ( short , long )] 32disable : Vec < InputMod >, 33/// Enable the latest versions of all mods. 34# [ structopt ( short = "l" , long )] 35enable_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 )] 39enable : Vec < InputMod >, 40/// Ignore mod dependencies when enabling them. 41# [ structopt ( long )] 42ignore_dependencies : bool , 43/// Include the base mod when calling `disable-all`. 44# [ structopt ( long )] 45include_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 )] 48remove : Vec < InputMod >, 49} 50 51fn main () ->Result <(), Box < dyn Error >> { 52let app =App :: from_args (); 53 54let mut set =ModsSet :: new ( & app. dir ) ?; 55 56for mod_identin app. remove . iter () { 57 set. remove ( mod_ident) ?; 58} 59 60if app. dedup { 61 set. dedup () ?; 62} 63 64if app. disable_all { 65 set. disable_all ( app. include_base_mod ); 66} 67 68if app. enable_all { 69 set. enable_all (); 70} 71 72for mod_identin app. disable . iter () { 73 set. disable ( mod_ident) ?; 74} 75 76if app. enable . len () >0 { 77let enabled_names: HashSet < String > =HashSet :: new (); 78let to_enable = app. enable . clone (); 79 80for mod_identin to_enable. iter () { 81 set. enable ( mod_ident) ?; 82} 83} 84 85 set. write_mod_list () ?; 86 87Ok (()) 88}