11package cmd
22
33import (
4+ "errors"
45 "fmt"
56 "os"
7+ "strings"
68
79 "github.com/code-game-project/go-utils/cgfile"
810 "github.com/code-game-project/go-utils/external"
@@ -25,14 +27,31 @@ var buildCmd = &cobra.Command{
2527 data .URL = external .TrimURL (data .URL )
2628 abort (data .Write ("" ))
2729
28- cmdArgs := []string {"build" }
29- cmdArgs = append (cmdArgs , args ... )
30-
3130 output , err := cmd .Flags ().GetString ("output" )
3231 abort (err )
32+
33+ os , err := cmd .Flags ().GetString ("os" )
34+ abort (err )
35+ os = strings .ToLower (os )
36+ if os != "current" && os != "windows" && os != "macos" && os != "linux" {
37+ abort (fmt .Errorf ("OS '%s' is not supported. (possible values: windows, macos, linux)" , os ))
38+ }
39+ arch , err := cmd .Flags ().GetString ("arch" )
40+ abort (err )
41+ arch = strings .ToLower (arch )
42+ if arch != "current" && arch != "x64" && arch != "x86" && arch != "arm32" && arch != "arm64" {
43+ abort (fmt .Errorf ("Architecture '%s' is not supported. (possible values: x64, x86, arm32, arm64)" , arch ))
44+ }
45+
46+ if os == "macos" && arch == "arm32" {
47+ abort (errors .New ("macOS does not support arm32. Try arm64 instead." ))
48+ }
49+
3350 buildData := modules.BuildData {
3451 Lang : data .Lang ,
3552 Output : output ,
53+ OS : os ,
54+ Arch : arch ,
3655 }
3756 switch data .Lang {
3857 case "cs" , "go" , "js" , "ts" :
@@ -47,4 +66,6 @@ var buildCmd = &cobra.Command{
4766func init () {
4867 rootCmd .AddCommand (buildCmd )
4968 buildCmd .Flags ().StringP ("output" , "o" , "" , "The name of the output file." )
69+ buildCmd .Flags ().String ("os" , "current" , "The target OS for compiled languages. (possible values: windows, macos, linux)" )
70+ buildCmd .Flags ().String ("arch" , "current" , "The target architecture for compiled languages. (possible values: x64, x86, arm32, arm64)" )
5071}
0 commit comments