Skip to content

Commit 722138d

Browse files
committed
Ban use of os.Exit from cli package
1 parent 6a4a1dc commit 722138d

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

internal/cli/board/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func runListCommand(cmd *cobra.Command, args []string) {
6060

6161
if watch {
6262
watchList(cmd, inst)
63-
os.Exit(0)
63+
return
6464
}
6565

6666
ports, discvoeryErrors, err := board.List(&rpc.BoardListRequest{

internal/cli/cli_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,15 @@ func inspect(t *testing.T, fset *token.FileSet, node ast.Node) bool {
7070
t.Fail()
7171
}
7272
case *ast.SelectorExpr:
73-
wanted := map[string]bool{
74-
"os.Stdout": true,
75-
"os.Stderr": true,
76-
"os.Stdin": true,
73+
wanted := map[string]string{
74+
"os.Stdout": "%s: object `%s` should not be used in this package (use `feedback.*` instead)\n",
75+
"os.Stderr": "%s: object `%s` should not be used in this package (use `feedback.*` instead)\n",
76+
"os.Stdin": "%s: object `%s` should not be used in this package (use `feedback.*` instead)\n",
77+
"os.Exit": "%s: function `%s` should not be used in this package (use `return` or `feedback.FatalError` instead)\n",
7778
}
7879
name := expr(n)
79-
if wanted[name] {
80-
fmt.Printf("%s: object `%s` should not be used in this package (use `feedback.*` instead)\n", fset.Position(n.Pos()), name)
80+
if msg, banned := wanted[name]; banned {
81+
fmt.Printf(msg, fset.Position(n.Pos()), name)
8182
t.Fail()
8283
}
8384
}

internal/cli/compile/compile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
309309
feedback.FatalError(err, feedback.ErrGeneric)
310310
}
311311
feedback.PrintResult(stdIORes())
312-
os.Exit(0)
312+
return
313313
}
314314

315315
stdIO := stdIORes()

0 commit comments

Comments
 (0)