From 1cee7fcaa07bb7e1b3568245ac236677ba6e83bc Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Mon, 22 Jul 2024 15:56:22 +0200 Subject: [PATCH] Simplified system command --- src/build/config/init.go | 32 +++++++++++++++++++------------- src/cli/System.go | 27 +++++++-------------------- 2 files changed, 26 insertions(+), 33 deletions(-) diff --git a/src/build/config/init.go b/src/build/config/init.go index 31732e8..5f0f972 100644 --- a/src/build/config/init.go +++ b/src/build/config/init.go @@ -8,33 +8,39 @@ import ( ) var ( - Executable string - Root string - Library string + Executable string + Root string + Library string + WorkingDirectory string ) func init() { debug.SetGCPercent(-1) - executable, err := os.Executable() + + var err error + Executable, err = os.Executable() if err != nil { panic(err) } - Executable = executable - Root = filepath.Dir(executable) + WorkingDirectory, err = os.Getwd() + + if err != nil { + panic(err) + } + + Root = filepath.Dir(Executable) Library = filepath.Join(Root, "lib") stat, err := os.Stat(Library) - if !os.IsNotExist(err) && stat != nil && stat.IsDir() { - return + if os.IsNotExist(err) || stat == nil || !stat.IsDir() { + findLibrary() } +} - dir, err := os.Getwd() - - if err != nil { - panic(err) - } +func findLibrary() { + dir := WorkingDirectory for { Library = path.Join(dir, "lib") diff --git a/src/cli/System.go b/src/cli/System.go index 831576c..5a26b37 100644 --- a/src/cli/System.go +++ b/src/cli/System.go @@ -2,35 +2,22 @@ package cli import ( "fmt" - "os" "runtime" + "strconv" + + "git.akyoto.dev/cli/q/src/build/config" ) // System shows system information. func System(args []string) int { line := "%-19s%s\n" - fmt.Printf(line, "Platform:", runtime.GOOS) fmt.Printf(line, "Architecture:", runtime.GOARCH) fmt.Printf(line, "Go:", runtime.Version()) - - // Directory - directory, err := os.Getwd() - - if err == nil { - fmt.Printf(line, "Directory:", directory) - } else { - fmt.Printf(line, "Directory:", err.Error()) - } - - // Compiler - executable, err := os.Executable() - - if err == nil { - fmt.Printf(line, "Compiler:", executable) - } else { - fmt.Printf(line, "Compiler:", err.Error()) - } + fmt.Printf(line, "Directory:", config.WorkingDirectory) + fmt.Printf(line, "Compiler:", config.Executable) + fmt.Printf(line, "Library:", config.Library) + fmt.Printf(line, "Threads:", strconv.Itoa(runtime.NumCPU())) return 0 }