add cli flag to add missing mods in enabled state
This commit is contained in:
parent
636c6f9143
commit
c9eaba2737
|
@ -14,9 +14,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
modsdir, infile, outfile string
|
modsdir, infile, outfile string
|
||||||
mods modlist.Modlist
|
mods modlist.Modlist
|
||||||
clobber, addmissing bool
|
clobber, addmissing, missingstate bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var cfg config
|
var cfg config
|
||||||
|
@ -79,6 +79,12 @@ func main() {
|
||||||
Required: false,
|
Required: false,
|
||||||
Usage: "don't automatically add mods missing from infile",
|
Usage: "don't automatically add mods missing from infile",
|
||||||
},
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "enable-missing",
|
||||||
|
Aliases: []string{"e"},
|
||||||
|
Required: false,
|
||||||
|
Usage: "Missing mods are added in enabled state",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Before: func(ctx *cli.Context) error {
|
Before: func(ctx *cli.Context) error {
|
||||||
// Setup logger
|
// Setup logger
|
||||||
|
@ -93,6 +99,7 @@ func main() {
|
||||||
// Bool flags
|
// Bool flags
|
||||||
cfg.clobber = ctx.Bool("clobber")
|
cfg.clobber = ctx.Bool("clobber")
|
||||||
cfg.addmissing = !ctx.Bool("no-add-missing")
|
cfg.addmissing = !ctx.Bool("no-add-missing")
|
||||||
|
cfg.missingstate = ctx.Bool("enable-missing")
|
||||||
|
|
||||||
// Deal with in/out file
|
// Deal with in/out file
|
||||||
var in = ctx.String("infile")
|
var in = ctx.String("infile")
|
||||||
|
@ -124,7 +131,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.addmissing {
|
if cfg.addmissing {
|
||||||
err = modlist.AddModsNotInList(cfg.modsdir, &cfg.mods)
|
err = modlist.AddModsNotInList(cfg.modsdir, &cfg.mods, cfg.missingstate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,7 +152,7 @@ func ReadFromFile(filename string) (Modlist, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddModsNotInList finds mod archives in the mod folder that aren't in the modlist, and adds them.
|
// AddModsNotInList finds mod archives in the mod folder that aren't in the modlist, and adds them.
|
||||||
func AddModsNotInList(modsdir string, mods *Modlist) error {
|
func AddModsNotInList(modsdir string, mods *Modlist, state bool) error {
|
||||||
r := regexp.MustCompile(fileRegex)
|
r := regexp.MustCompile(fileRegex)
|
||||||
|
|
||||||
files, err := os.ReadDir(modsdir)
|
files, err := os.ReadDir(modsdir)
|
||||||
|
@ -167,10 +167,10 @@ func AddModsNotInList(modsdir string, mods *Modlist) error {
|
||||||
version := groups[0][2]
|
version := groups[0][2]
|
||||||
|
|
||||||
if !mods.HasMod(name) {
|
if !mods.HasMod(name) {
|
||||||
log.Info("Found %s not in modlist, adding v%s in disabled state.", name, version)
|
log.Infof("Found %s not in modlist, adding v%s in disabled state.", name, version)
|
||||||
mods.Mods = append(mods.Mods, Mod{
|
mods.Mods = append(mods.Mods, Mod{
|
||||||
Name: name,
|
Name: name,
|
||||||
Enabled: false,
|
Enabled: state,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue