mirror of
https://github.com/EnumeratedDev/stormfetch.git
synced 2026-09-16 07:56:12 +00:00
Rewrite 'GetDistroAsciiArt' function
This commit is contained in:
+2
-1
@@ -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()
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-23
@@ -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 defaultAscii
|
|
||||||
}
|
|
||||||
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))
|
|
||||||
if err != nil {
|
|
||||||
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 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return defaultAscii
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetArch() string {
|
func GetArch() string {
|
||||||
|
|||||||
Reference in New Issue
Block a user