Simplified system command

This commit is contained in:
Eduard Urbach 2024-07-22 15:56:22 +02:00
parent 21017e6378
commit 1cee7fcaa0
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
2 changed files with 26 additions and 33 deletions

View File

@ -11,30 +11,36 @@ var (
Executable string Executable string
Root string Root string
Library string Library string
WorkingDirectory string
) )
func init() { func init() {
debug.SetGCPercent(-1) debug.SetGCPercent(-1)
executable, err := os.Executable()
var err error
Executable, err = os.Executable()
if err != nil { if err != nil {
panic(err) panic(err)
} }
Executable = executable WorkingDirectory, err = os.Getwd()
Root = filepath.Dir(executable)
if err != nil {
panic(err)
}
Root = filepath.Dir(Executable)
Library = filepath.Join(Root, "lib") Library = filepath.Join(Root, "lib")
stat, err := os.Stat(Library) stat, err := os.Stat(Library)
if !os.IsNotExist(err) && stat != nil && stat.IsDir() { if os.IsNotExist(err) || stat == nil || !stat.IsDir() {
return findLibrary()
}
} }
dir, err := os.Getwd() func findLibrary() {
dir := WorkingDirectory
if err != nil {
panic(err)
}
for { for {
Library = path.Join(dir, "lib") Library = path.Join(dir, "lib")

View File

@ -2,35 +2,22 @@ package cli
import ( import (
"fmt" "fmt"
"os"
"runtime" "runtime"
"strconv"
"git.akyoto.dev/cli/q/src/build/config"
) )
// System shows system information. // System shows system information.
func System(args []string) int { func System(args []string) int {
line := "%-19s%s\n" line := "%-19s%s\n"
fmt.Printf(line, "Platform:", runtime.GOOS) fmt.Printf(line, "Platform:", runtime.GOOS)
fmt.Printf(line, "Architecture:", runtime.GOARCH) fmt.Printf(line, "Architecture:", runtime.GOARCH)
fmt.Printf(line, "Go:", runtime.Version()) fmt.Printf(line, "Go:", runtime.Version())
fmt.Printf(line, "Directory:", config.WorkingDirectory)
// Directory fmt.Printf(line, "Compiler:", config.Executable)
directory, err := os.Getwd() fmt.Printf(line, "Library:", config.Library)
fmt.Printf(line, "Threads:", strconv.Itoa(runtime.NumCPU()))
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())
}
return 0 return 0
} }