id3tool/internal/config/config.go

65 lines
1.4 KiB
Go
Raw Permalink Normal View History

2024-05-28 13:48:19 +02:00
package config
import (
"os"
"strconv"
2024-05-28 13:48:19 +02:00
"strings"
"git.velvettear.de/velvettear/loggo"
)
var Directory string
var FramesToKeep []string
var Timeout int
2024-05-28 13:48:19 +02:00
// check program arguments and set variables accordingly
func CheckArguments() {
argsCount := len(os.Args)
var framesToKeep []string
for index := 0; index < argsCount; index++ {
switch os.Args[index] {
case "-d":
fallthrough
case "--debug":
loggo.SetLogLevel(loggo.DebugLevel)
case "-f":
fallthrough
case "--frames":
framesToKeep = strings.Split(os.Args[index+1], ",")
case "-t":
fallthrough
case "--timeout":
Timeout, _ = strconv.Atoi(os.Args[index+1])
2024-05-28 13:48:19 +02:00
case "-h":
fallthrough
case "--help":
printHelp()
}
}
Directory = os.Args[len(os.Args)-1]
if len(framesToKeep) == 0 {
FramesToKeep = []string{"APIC", "TALB", "TCON", "TDAT", "TDRC", "TIT2", "TPOS", "TPE1", "TPE2", "TRCK"}
} else {
for _, frame := range framesToKeep {
FramesToKeep = append(FramesToKeep, strings.ToUpper(strings.TrimSpace(frame)))
}
}
if Timeout <= 0 {
Timeout = 30
}
2024-05-28 13:48:19 +02:00
}
// print the help
func printHelp() {
loggo.SetLogFormat("# $MESSAGE$")
loggo.Info("tagcleaner")
loggo.Info("Daniel Sommer <daniel.sommer@velvettear.de>")
loggo.Info("\n")
loggo.Info("usage:\ttagcleaner [options] <directory>")
loggo.Info("\n")
loggo.Info("options:")
loggo.Info("\t-d | --debug\tenable debug mode")
loggo.Info("\t-f | --frames\tframes to keep")
os.Exit(0)
}