From 1ef3daf251ef6e53624435fc821293c7e1cdf736 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Wed, 6 May 2020 12:22:52 +0100 Subject: [PATCH] clarify usage text, add help flags Also remove the -toolexec equivalent, as it's becoming longer now that we have GARBLE_DIR, and it might become out of date in the future again. We don't want users to assume it will work forever. --- README.md | 4 +--- main.go | 14 ++++++++++++-- testdata/scripts/help.txt | 18 ++++++++++++++---- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 9c25b96..b93d5db 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,7 @@ Obfuscate a Go build. Requires Go 1.13 or later. garble build [build flags] [packages] -which is equivalent to the longer: - - GARBLE_DIR="$PWD" go build -a -trimpath -toolexec=garble [build flags] [packages] +See `garble -h` for up to date usage information. ### Purpose diff --git a/main.go b/main.go index 02f7ba8..23ef67e 100644 --- a/main.go +++ b/main.go @@ -38,9 +38,13 @@ Usage of garble: garble build [build flags] [packages] -which is equivalent to the longer: +The tool supports wrapping the following Go commands - run "garble cmd [args]" +instead of "go cmd [args]" to add obfuscation: - go build -a -trimpath -toolexec=garble [build flags] [packages] + build + test + +garble does not have flags of its own at this moment. `[1:]) flagSet.PrintDefaults() os.Exit(2) @@ -144,7 +148,13 @@ func mainErr(args []string) error { // If we recognise an argument, we're not running within -toolexec. switch cmd := args[0]; cmd { + case "help": + flagSet.Usage() case "build", "test": + switch args[1] { + case "-h", "-help", "--help": + flagSet.Usage() + } wd, err := os.Getwd() if err != nil { return err diff --git a/testdata/scripts/help.txt b/testdata/scripts/help.txt index 37746d7..bb3048c 100644 --- a/testdata/scripts/help.txt +++ b/testdata/scripts/help.txt @@ -1,14 +1,24 @@ ! garble -stderr -count=1 'Usage of' -stderr '\tgo build' +stderr -count=1 'Usage of garble' +stderr 'garble cmd' +! stderr 'usage: go build' ! stdout . ! garble -h -stderr 'Usage of' +stderr 'Usage of garble' +! stdout . + +! garble help +stderr 'Usage of garble' +! stdout . + +! garble build -h +stderr 'Usage of garble' +! stderr 'usage: go build' ! stdout . ! garble -badflag -stderr 'Usage of' +stderr 'Usage of garble' ! stdout . ! garble badcmd