From 5ad26495fc86527bbfe75ac6b46528d49a373676 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Fri, 8 Jun 2018 00:03:23 +0200 Subject: main: cut down "flag provided but not defined" error message Don't dump the help text on the unsuspecting user, but give a short error message: $ gocryptfs -foobar flag provided but not defined: -foobar Invalid command line: gocryptfs -foobar. Try 'gocryptfs -help'. For comparison: This is what cp does: $ cp --foo cp: unrecognized option '--foo' Try 'cp --help' for more information. And this what we used to do: $ gocryptfs -foobar flag provided but not defined: -foobar gocryptfs v1.4.4-45-gfb772da; go-fuse v20170619-35-gb16719c; 2018-06-08 go1.10.2 Usage: gocryptfs -init|-passwd|-info [OPTIONS] CIPHERDIR or gocryptfs [OPTIONS] CIPHERDIR MOUNTPOINT Common Options (use -hh to show all): -aessiv Use AES-SIV encryption (with -init) -allow_other Allow other users to access the mount -config Custom path to config file -ctlsock Create control socket at location -extpass Call external program to prompt for the password -fg Stay in the foreground -fusedebug Debug FUSE calls -h, -help This short help text -hh Long help text with all options -init Initialize encrypted directory -info Display information about encrypted directory -masterkey Mount with explicit master key instead of password -nonempty Allow mounting over non-empty directory -nosyslog Do not redirect log messages to syslog -passfile Read password from file -passwd Change password -plaintextnames Do not encrypt file names (with -init) -q, -quiet Silence informational messages -reverse Enable reverse mode -ro Mount read-only -speed Run crypto speed test -version Print version information -- Stop option parsing You passed: "-foobar" flag provided but not defined: -foobar --- cli_args.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'cli_args.go') diff --git a/cli_args.go b/cli_args.go index 76876d6..08b3186 100644 --- a/cli_args.go +++ b/cli_args.go @@ -103,7 +103,7 @@ func parseCliOpts() (args argContainer) { } flagSet = flag.NewFlagSet(tlog.ProgramName, flag.ContinueOnError) - flagSet.Usage = helpShort + flagSet.Usage = func() {} flagSet.BoolVar(&args.debug, "d", false, "") flagSet.BoolVar(&args.debug, "debug", false, "Enable debug output") flagSet.BoolVar(&args.fusedebug, "fusedebug", false, "Enable fuse library debug output") @@ -169,11 +169,11 @@ func parseCliOpts() (args argContainer) { // Actual parsing err = flagSet.Parse(os.Args[1:]) if err == flag.ErrHelp { + helpShort() os.Exit(0) } if err != nil { - tlog.Warn.Printf("You passed: %s", prettyArgs()) - tlog.Fatal.Printf("%v", err) + tlog.Fatal.Printf("Invalid command line: %s. Try '%s -help'.", prettyArgs(), tlog.ProgramName) os.Exit(exitcodes.Usage) } // "-openssl" needs some post-processing @@ -225,7 +225,7 @@ func parseCliOpts() (args argContainer) { // prettyArgs pretty-prints the command-line arguments. func prettyArgs() string { - pa := fmt.Sprintf("%q", os.Args[1:]) + pa := fmt.Sprintf("%v", os.Args) // Get rid of "[" and "]" pa = pa[1 : len(pa)-1] return pa -- cgit v1.2.3