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