Clarify error for soong_ui failing to parse args

Test: m soong_ui and give invalid command line args
Change-Id: I7b4479b392d953bd1d87218184c5ed2143568a07
This commit is contained in:
Liz Kammer 2020-10-15 11:07:13 -07:00
parent 38fa0f5a77
commit 0e7993e3d2

View file

@ -119,9 +119,9 @@ func inList(s string, list []string) bool {
func main() { func main() {
buildStarted := time.Now() buildStarted := time.Now()
c, args := getCommand(os.Args) c, args, err := getCommand(os.Args)
if c == nil { if err != nil {
fmt.Fprintf(os.Stderr, "The `soong` native UI is not yet available.\n") fmt.Fprintf(os.Stderr, "Error parsing `soong` args: %s.\n", err)
os.Exit(1) os.Exit(1)
} }
@ -479,14 +479,14 @@ func make(ctx build.Context, config build.Config, _ []string, logsDir string) {
// getCommand finds the appropriate command based on args[1] flag. args[0] // getCommand finds the appropriate command based on args[1] flag. args[0]
// is the soong_ui filename. // is the soong_ui filename.
func getCommand(args []string) (*command, []string) { func getCommand(args []string) (*command, []string, error) {
if len(args) < 2 { if len(args) < 2 {
return nil, args return nil, nil, fmt.Errorf("Too few arguments: %q", args)
} }
for _, c := range commands { for _, c := range commands {
if c.flag == args[1] { if c.flag == args[1] {
return &c, args[2:] return &c, args[2:], nil
} }
// special case for --make-mode: if soong_ui was called from // special case for --make-mode: if soong_ui was called from
@ -495,11 +495,11 @@ func getCommand(args []string) (*command, []string) {
// TODO: Remove this hack once it has been fixed. // TODO: Remove this hack once it has been fixed.
if c.flag == makeModeFlagName { if c.flag == makeModeFlagName {
if inList(makeModeFlagName, args) { if inList(makeModeFlagName, args) {
return &c, args[1:] return &c, args[1:], nil
} }
} }
} }
// command not found // command not found
return nil, args return nil, nil, fmt.Errorf("Command not found: %q", args)
} }