mirror of
https://github.com/EnumeratedDev/stormfetch.git
synced 2026-09-16 07:56:12 +00:00
Add 'config' flag
This commit is contained in:
+12
-10
@@ -22,20 +22,22 @@ var config = StormfetchConfig{
|
||||
}
|
||||
|
||||
func readConfig() {
|
||||
// Get home directory
|
||||
userConfigDir, _ := os.UserConfigDir()
|
||||
if ConfigPath == "" {
|
||||
// Get home directory
|
||||
userConfigDir, _ := os.UserConfigDir()
|
||||
|
||||
// Find valid config directory
|
||||
if _, err := os.Stat(path.Join(userConfigDir, "stormfetch/config.yml")); err == nil {
|
||||
configPath = path.Join(userConfigDir, "stormfetch/config.yml")
|
||||
} else if _, err := os.Stat(path.Join(SystemConfigDir, "stormfetch/config.yml")); err == nil {
|
||||
configPath = path.Join(SystemConfigDir, "stormfetch/config.yml")
|
||||
} else {
|
||||
log.Fatalf("Config file not found: %s", err.Error())
|
||||
// Find valid config directory
|
||||
if _, err := os.Stat(path.Join(userConfigDir, "stormfetch/config.yml")); err == nil {
|
||||
ConfigPath = path.Join(userConfigDir, "stormfetch/config.yml")
|
||||
} else if _, err := os.Stat(path.Join(SystemConfigDir, "stormfetch/config.yml")); err == nil {
|
||||
ConfigPath = path.Join(SystemConfigDir, "stormfetch/config.yml")
|
||||
} else {
|
||||
log.Fatalf("Config file not found: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// Parse config
|
||||
bytes, err := os.ReadFile(configPath)
|
||||
bytes, err := os.ReadFile(ConfigPath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
+3
-3
@@ -15,19 +15,19 @@ var SystemConfigDir = "/etc/"
|
||||
|
||||
// Flag variables
|
||||
var ShowVersion = false
|
||||
var ConfigPath = ""
|
||||
var ShowModuleTimeTaken = false
|
||||
|
||||
var configPath = ""
|
||||
|
||||
func main() {
|
||||
readConfig()
|
||||
parseFlags()
|
||||
readConfig()
|
||||
initializeModuleMap()
|
||||
run()
|
||||
}
|
||||
|
||||
func parseFlags() {
|
||||
flag.BoolVar(&ShowVersion, "version", false, "Show Stormfetch version")
|
||||
flag.StringVar(&ConfigPath, "config", "", "Use the specified config file")
|
||||
flag.BoolVar(&ShowModuleTimeTaken, "time-taken", false, "Show time taken to execute each module")
|
||||
flag.StringVar(&config.Ascii, "ascii", config.Ascii, "Set distro ascii")
|
||||
flag.StringVar(&config.DistroName, "distro-name", config.DistroName, "Set distro name")
|
||||
|
||||
Reference in New Issue
Block a user