From 4b9ef72fe2dcbd519bf895fee411946ab59087cf Mon Sep 17 00:00:00 2001 From: Jeff Gaston Date: Thu, 5 Oct 2017 18:33:23 -0700 Subject: [PATCH] Add usage message to androidmk Test: androidmk 2>&1 | grep usage && androidmk --help 2>&1 | grep usage && echo ok Bug: 67426255 Change-Id: I1e5033321c62c6744672f2ea435a422a4b9bd3da --- androidmk/cmd/androidmk/androidmk.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/androidmk/cmd/androidmk/androidmk.go b/androidmk/cmd/androidmk/androidmk.go index 5fad5860f..a49f6200b 100644 --- a/androidmk/cmd/androidmk/androidmk.go +++ b/androidmk/cmd/androidmk/androidmk.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "flag" "fmt" "io/ioutil" "os" @@ -15,6 +16,13 @@ import ( bpparser "github.com/google/blueprint/parser" ) +var usage = func() { + fmt.Fprintf(os.Stderr, "usage: androidmk [flags] \n"+ + "\nandroidmk parses as an Android.mk file and attempts to output an analogous Android.bp file (to standard out)\n") + flag.PrintDefaults() + os.Exit(1) +} + // TODO: non-expanded variables with expressions type bpFile struct { @@ -85,7 +93,13 @@ type conditional struct { } func main() { - b, err := ioutil.ReadFile(os.Args[1]) + flag.Usage = usage + flag.Parse() + if len(flag.Args()) != 1 { + usage() + } + filePathToRead := flag.Arg(0) + b, err := ioutil.ReadFile(filePathToRead) if err != nil { fmt.Println(err.Error()) return