Skip to content

Commit 31d7534

Browse files
authored
Detect operating system (#114)
detect operating system
1 parent d957eb6 commit 31d7534

File tree

6 files changed

+27
-14
lines changed

6 files changed

+27
-14
lines changed

checks/checks.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"os"
1111
"os/exec"
1212
"regexp"
13+
"runtime"
1314
"strings"
1415
"time"
1516

@@ -22,7 +23,14 @@ func runCLICommand(command api.CLIStepCLICommand, variables map[string]string) (
2223
finalCommand := InterpolateVariables(command.Command, variables)
2324
result.FinalCommand = finalCommand
2425

25-
cmd := exec.Command("sh", "-c", finalCommand)
26+
var cmd *exec.Cmd
27+
28+
if runtime.GOOS == "windows" {
29+
cmd = exec.Command("powershell", "-Command", finalCommand)
30+
} else {
31+
cmd = exec.Command("sh", "-c", finalCommand)
32+
}
33+
2634
cmd.Env = append(os.Environ(), "LANG=en_US.UTF-8")
2735
b, err := cmd.CombinedOutput()
2836
if ee, ok := err.(*exec.ExitError); ok {

client/lessons.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ const BaseURLOverrideRequired = "override"
2121

2222
type CLIData struct {
2323
// ContainsCompleteDir bool
24-
BaseURLDefault string
25-
Steps []CLIStep
24+
BaseURLDefault string
25+
Steps []CLIStep
26+
AllowedOperatingSystems []string
2627
}
2728

2829
type CLIStep struct {

cmd/submit.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"errors"
55
"fmt"
6+
"runtime"
67

78
"github.com/bootdotdev/bootdev/checks"
89
api "github.com/bootdotdev/bootdev/client"
@@ -43,6 +44,18 @@ func submissionHandler(cmd *cobra.Command, args []string) error {
4344
}
4445

4546
data := lesson.Lesson.LessonDataCLI.CLIData
47+
48+
isAllowedOS := false
49+
for _, system := range data.AllowedOperatingSystems {
50+
if system == runtime.GOOS {
51+
isAllowedOS = true
52+
}
53+
}
54+
55+
if !isAllowedOS {
56+
return fmt.Errorf("lesson is not supported for your operating system: \"%s\". Try again with one of the following: %v", runtime.GOOS, data.AllowedOperatingSystems)
57+
}
58+
4659
overrideBaseURL := viper.GetString("override_base_url")
4760
if overrideBaseURL != "" {
4861
fmt.Printf("Using overridden base_url: %v\n", overrideBaseURL)

main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build darwin || linux
2-
31
package main
42

53
import (
@@ -15,7 +13,7 @@ import (
1513
var version string
1614

1715
func main() {
18-
err := cmd.Execute(strings.Trim(version, "\n"))
16+
err := cmd.Execute(strings.TrimSpace(version))
1917
if err != nil {
2018
os.Exit(1)
2119
}

main_windows.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.20.3
1+
v1.20.4

0 commit comments

Comments
 (0)