cmd/cue/cmd: don't use os.Exit and fix error output

Fixes #125

Change-Id: Iac275218e1eb6586a2a2f2345454082378571972
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/3381
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
diff --git a/cmd/cue/cmd/root.go b/cmd/cue/cmd/root.go
index 71c9760..bf13a2a 100644
--- a/cmd/cue/cmd/root.go
+++ b/cmd/cue/cmd/root.go
@@ -16,9 +16,7 @@
 
 import (
 	"context"
-	"fmt"
 	"io"
-	"os"
 	"strings"
 
 	"cuelang.org/go/cue/errors"
@@ -233,10 +231,11 @@
 	}
 	_, err = addCustom(cmd, rootCmd, commandSection, args[0], tools)
 	if err != nil {
-		stderr := cmd.Stderr()
-		fmt.Fprintf(stderr, "command %s %q is not defined\n", commandSection, args[0])
-		fmt.Println(stderr, "Run 'cue help' to show available commands.")
-		os.Exit(1)
+		return cmd, errors.Newf(token.NoPos,
+			"command %s %q is not defined\n"+
+				"Run 'cue help' to show available commands.",
+			commandSection, args[0],
+		)
 	}
 	return cmd, nil
 }