From 782516301f02ca59d4314e74fb20a90a374ba5b2 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Thu, 5 Mar 2015 14:55:52 -0500 Subject: [PATCH] cmd/eg: improve usage and help messages eg with no arguments prints its usage, including a hand-written flag summary. eg -help shows the detailed help message. Change-Id: I615d8de3985ced1e86e9d7cafa9ef679079b249c Reviewed-on: https://go-review.googlesource.com/6951 Reviewed-by: Robert Griesemer --- cmd/eg/eg.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/cmd/eg/eg.go b/cmd/eg/eg.go index 0ad43314..5c2c28d8 100644 --- a/cmd/eg/eg.go +++ b/cmd/eg/eg.go @@ -29,9 +29,14 @@ var ( const usage = `eg: an example-based refactoring tool. Usage: eg -t template.go [-w] [-transitive] ... --t template.go specifies the template file (use -help to see explanation) --w causes files to be re-written in place. --transitive causes all dependencies to be refactored too. + +-help show detailed help message +-t template.go specifies the template file (use -help to see explanation) +-w causes files to be re-written in place. +-transitive causes all dependencies to be refactored too. +-v show verbose matcher diagnostics +-beforeedit cmd a command to exec before each file is modified. + "{}" represents the name of the file. ` + loader.FromArgsUsage func main() { @@ -50,6 +55,11 @@ func doMain() error { os.Exit(2) } + if len(args) == 0 { + fmt.Fprint(os.Stderr, usage) + os.Exit(1) + } + if *templateFlag == "" { return fmt.Errorf("no -t template.go file specified") } @@ -62,11 +72,6 @@ func doMain() error { // The first Created package is the template. conf.CreateFromFilenames("template", *templateFlag) - if len(args) == 0 { - fmt.Fprint(os.Stderr, usage) - os.Exit(1) - } - if _, err := conf.FromArgs(args, true); err != nil { return err }