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
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")

View File

@ -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
}