Rewrite 'GetDistroAsciiArt' function

This commit is contained in:
2025-12-22 12:26:42 +02:00
parent 3131d94429
commit 051301aacd
2 changed files with 24 additions and 27 deletions
+2 -1
View File
@@ -16,6 +16,7 @@ var SystemConfigDir = "/etc/"
// Flag variables // Flag variables
var ShowVersion = false var ShowVersion = false
var ConfigPath = "" var ConfigPath = ""
var Ascii = ""
var ShowModuleTimeTaken = false var ShowModuleTimeTaken = false
func main() { func main() {
@@ -29,7 +30,7 @@ func parseFlags() {
flag.BoolVar(&ShowVersion, "version", false, "Show Stormfetch version") flag.BoolVar(&ShowVersion, "version", false, "Show Stormfetch version")
flag.StringVar(&ConfigPath, "config", "", "Use the specified config file") flag.StringVar(&ConfigPath, "config", "", "Use the specified config file")
flag.BoolVar(&ShowModuleTimeTaken, "time-taken", false, "Show time taken to execute each module") 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(&Ascii, "ascii", "", "Set distro ascii")
flag.StringVar(&config.DistroName, "distro-name", config.DistroName, "Set distro name") flag.StringVar(&config.DistroName, "distro-name", config.DistroName, "Set distro name")
flag.Parse() flag.Parse()
} }
+22 -26
View File
@@ -65,39 +65,35 @@ func GetDistroAsciiArt() string {
(| | ) (| | )
/'\_ _/'\ /'\_ _/'\
\___)=(___/ ` \___)=(___/ `
var id string
if config.Ascii == "auto" { // Get ascii name to use
id = GetDistroInfo().ID var asciiName string
if Ascii != "" {
asciiName = Ascii
} else if config.Ascii == "auto" {
asciiName = GetDistroInfo().ID
} else { } else {
id = config.Ascii asciiName = config.Ascii
} }
// Check for ascii art in home directory
userConfDir, err := os.UserConfigDir() userConfDir, err := os.UserConfigDir()
if err != nil { if err == nil {
if _, err := os.Stat(path.Join(SystemConfigDir, "stormfetch/ascii/", id)); err == nil { if _, err := os.Stat(path.Join(userConfDir, "stormfetch/ascii/", asciiName)); err == nil {
bytes, err := os.ReadFile(path.Join(SystemConfigDir, "stormfetch/ascii/", id)) if bytes, err := os.ReadFile(path.Join(userConfDir, "stormfetch/ascii/", asciiName)); err == nil {
if err != nil { return string(bytes)
return defaultAscii
} }
}
}
// Check for ascii art in system config directory
if _, err := os.Stat(path.Join(SystemConfigDir, "stormfetch/ascii/", asciiName)); err == nil {
if bytes, err := os.ReadFile(path.Join(SystemConfigDir, "stormfetch/ascii/", asciiName)); err == nil {
return string(bytes) return string(bytes)
} else {
return defaultAscii
} }
} }
if _, err := os.Stat(path.Join(userConfDir, "stormfetch/ascii/", id)); err == nil {
bytes, err := os.ReadFile(path.Join(userConfDir, "stormfetch/ascii/", id)) return defaultAscii
if err != nil {
return defaultAscii
}
return string(bytes)
} else if _, err := os.Stat(path.Join(SystemConfigDir, "stormfetch/ascii/", id)); err == nil {
bytes, err := os.ReadFile(path.Join(SystemConfigDir, "stormfetch/ascii/", id))
if err != nil {
return defaultAscii
}
return strings.TrimRight(string(bytes), "\n\t ")
} else {
return defaultAscii
}
} }
func GetArch() string { func GetArch() string {