From 73ac76828905c25d29b598b958684f40958f19bd Mon Sep 17 00:00:00 2001 From: Nguyen Tran Hau Date: Wed, 14 Apr 2021 11:20:24 +0700 Subject: [PATCH] feat: prevent define os running at runtime (#2) Co-authored-by: Tran Hau --- main.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index aa9159b..f85e47f 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "fmt" "os" + "runtime" "github.com/fatih/color" "github.com/urfave/cli/v2" @@ -18,9 +19,25 @@ const ( currentDir = "." ) -var fmtErr = color.New(color.FgRed) +var ( + fmtErr = color.New(color.FgRed) + headerErr = fmt.Sprintf("[%s error]: ", appName) + + // denyOSes contains OS which is not supported + // go tool dist list + denyOSes = map[string]struct{}{ + "windows": struct{}{}, + } +) func main() { + // Prevent running at runtime + if _, ok := denyOSes[runtime.GOOS]; ok { + fmtErr.Print(headerErr) + fmt.Printf("OS %s is not supported right now\n", runtime.GOOS) + return + } + a := &action{} app := &cli.App{ @@ -50,8 +67,7 @@ func main() { } if err := app.Run(os.Args); err != nil { - // Highlight error - fmtErr.Printf("[%s error]: ", appName) + fmtErr.Print(headerErr) fmt.Printf("%s\n", err.Error()) } }