Add usage message to androidmk

Test: androidmk 2>&1 | grep usage && androidmk --help 2>&1 | grep usage && echo ok
Bug: 67426255
Change-Id: I1e5033321c62c6744672f2ea435a422a4b9bd3da
This commit is contained in:
Jeff Gaston 2017-10-05 18:33:23 -07:00
parent c21d11850d
commit 4b9ef72fe2
1 changed files with 15 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package main
import ( import (
"bytes" "bytes"
"flag"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
@ -15,6 +16,13 @@ import (
bpparser "github.com/google/blueprint/parser" bpparser "github.com/google/blueprint/parser"
) )
var usage = func() {
fmt.Fprintf(os.Stderr, "usage: androidmk [flags] <inputFile>\n"+
"\nandroidmk parses <inputFile> 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 // TODO: non-expanded variables with expressions
type bpFile struct { type bpFile struct {
@ -85,7 +93,13 @@ type conditional struct {
} }
func main() { 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 { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
return return