Skip to content

Commit 9a9bd40

Browse files
authored
Merge pull request #75 from Borwe/exits
Exiting: Make Exit(0) use Exit(1) if exiting because of errors
2 parents 10f7bb2 + 96f5433 commit 9a9bd40

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

main.go

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,41 +38,36 @@ func main() {
3838
help := styles.HelpStyle.Render("💡 Tumia exit() au toka() kuondoka")
3939
fmt.Println(lipgloss.JoinVertical(lipgloss.Left, NewLogo, "\n", help))
4040
repl.Start()
41-
os.Exit(0)
41+
return
4242
}
4343

4444
if len(args) == 2 {
45-
4645
switch args[1] {
4746
case "msaada", "-msaada", "--msaada", "help", "-help", "--help", "-h":
4847
fmt.Println(Help)
49-
os.Exit(0)
5048
case "version", "-version", "--version", "-v", "v", "--toleo", "-toleo":
5149
fmt.Println(NewLogo)
52-
os.Exit(0)
5350
case "-docs", "--docs", "-nyaraka", "--nyaraka":
5451
repl.Docs()
55-
os.Exit(0)
56-
}
52+
default:
53+
file := args[1]
5754

58-
file := args[1]
55+
if strings.HasSuffix(file, "nr") || strings.HasSuffix(file, ".sw") {
56+
contents, err := os.ReadFile(file)
57+
if err != nil {
58+
fmt.Println(styles.ErrorStyle.Render("Error: Nuru imeshindwa kusoma faili: ", args[1]))
59+
os.Exit(1)
60+
}
5961

60-
if strings.HasSuffix(file, "nr") || strings.HasSuffix(file, ".sw") {
61-
contents, err := os.ReadFile(file)
62-
if err != nil {
63-
fmt.Println(styles.ErrorStyle.Render("Error: Nuru imeshindwa kusoma faili: ", args[1]))
64-
os.Exit(0)
62+
repl.Read(string(contents))
63+
} else {
64+
fmt.Println(styles.ErrorStyle.Render("'"+file+"'", "sii faili sahihi. Tumia faili la '.nr' au '.sw'"))
65+
os.Exit(1)
6566
}
66-
67-
repl.Read(string(contents))
68-
} else {
69-
fmt.Println(styles.ErrorStyle.Render("'"+file+"'", "sii faili sahihi. Tumia faili la '.nr' au '.sw'"))
70-
os.Exit(0)
7167
}
72-
7368
} else {
7469
fmt.Println(styles.ErrorStyle.Render("Error: Operesheni imeshindikana boss."))
7570
fmt.Println(Help)
76-
os.Exit(0)
71+
os.Exit(1)
7772
}
7873
}

0 commit comments

Comments
 (0)