From b3aa757b3d1e7675786e6e19cc81fbbea5bf70e5 Mon Sep 17 00:00:00 2001 From: hbeckmann Date: Thu, 25 Sep 2025 15:22:57 -0600 Subject: [PATCH] detect operating system --- checks/checks.go | 10 +++++++++- client/lessons.go | 5 +++-- cmd/submit.go | 13 +++++++++++++ main.go | 4 +--- main_windows.go | 7 ------- version.txt | 2 +- 6 files changed, 27 insertions(+), 14 deletions(-) delete mode 100644 main_windows.go diff --git a/checks/checks.go b/checks/checks.go index d580e50..6a8a267 100644 --- a/checks/checks.go +++ b/checks/checks.go @@ -10,6 +10,7 @@ import ( "os" "os/exec" "regexp" + "runtime" "strings" "time" @@ -22,7 +23,14 @@ func runCLICommand(command api.CLIStepCLICommand, variables map[string]string) ( finalCommand := InterpolateVariables(command.Command, variables) result.FinalCommand = finalCommand - cmd := exec.Command("sh", "-c", finalCommand) + var cmd *exec.Cmd + + if runtime.GOOS == "windows" { + cmd = exec.Command("powershell", "-Command", finalCommand) + } else { + cmd = exec.Command("sh", "-c", finalCommand) + } + cmd.Env = append(os.Environ(), "LANG=en_US.UTF-8") b, err := cmd.CombinedOutput() if ee, ok := err.(*exec.ExitError); ok { diff --git a/client/lessons.go b/client/lessons.go index 4e53a18..bf96a27 100644 --- a/client/lessons.go +++ b/client/lessons.go @@ -21,8 +21,9 @@ const BaseURLOverrideRequired = "override" type CLIData struct { // ContainsCompleteDir bool - BaseURLDefault string - Steps []CLIStep + BaseURLDefault string + Steps []CLIStep + AllowedOperatingSystems []string } type CLIStep struct { diff --git a/cmd/submit.go b/cmd/submit.go index cf46e80..126014e 100644 --- a/cmd/submit.go +++ b/cmd/submit.go @@ -3,6 +3,7 @@ package cmd import ( "errors" "fmt" + "runtime" "github.com/bootdotdev/bootdev/checks" api "github.com/bootdotdev/bootdev/client" @@ -43,6 +44,18 @@ func submissionHandler(cmd *cobra.Command, args []string) error { } data := lesson.Lesson.LessonDataCLI.CLIData + + isAllowedOS := false + for _, system := range data.AllowedOperatingSystems { + if system == runtime.GOOS { + isAllowedOS = true + } + } + + if !isAllowedOS { + return fmt.Errorf("lesson is not supported for your operating system: \"%s\". Try again with one of the following: %v", runtime.GOOS, data.AllowedOperatingSystems) + } + overrideBaseURL := viper.GetString("override_base_url") if overrideBaseURL != "" { fmt.Printf("Using overridden base_url: %v\n", overrideBaseURL) diff --git a/main.go b/main.go index e300ba6..8c2846b 100644 --- a/main.go +++ b/main.go @@ -1,5 +1,3 @@ -//go:build darwin || linux - package main import ( @@ -15,7 +13,7 @@ import ( var version string func main() { - err := cmd.Execute(strings.Trim(version, "\n")) + err := cmd.Execute(strings.TrimSpace(version)) if err != nil { os.Exit(1) } diff --git a/main_windows.go b/main_windows.go deleted file mode 100644 index a3fc523..0000000 --- a/main_windows.go +++ /dev/null @@ -1,7 +0,0 @@ -//go:build windows - -package main - -func main() { - windows_is_not_supported_please_use_WSL() -} diff --git a/version.txt b/version.txt index 1940c46..5d3df1a 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -v1.20.3 +v1.20.4