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
This commit is contained in:
Jakob Unterwurzacher 2018-06-08 00:03:23 +02:00
parent fb772da697
commit 5ad26495fc
1 changed files with 4 additions and 4 deletions

View File

@ -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