Skip to content

Commit 5ad2649

Browse files
committed
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
1 parent fb772da commit 5ad2649

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

cli_args.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func parseCliOpts() (args argContainer) {
103103
}
104104

105105
flagSet = flag.NewFlagSet(tlog.ProgramName, flag.ContinueOnError)
106-
flagSet.Usage = helpShort
106+
flagSet.Usage = func() {}
107107
flagSet.BoolVar(&args.debug, "d", false, "")
108108
flagSet.BoolVar(&args.debug, "debug", false, "Enable debug output")
109109
flagSet.BoolVar(&args.fusedebug, "fusedebug", false, "Enable fuse library debug output")
@@ -169,11 +169,11 @@ func parseCliOpts() (args argContainer) {
169169
// Actual parsing
170170
err = flagSet.Parse(os.Args[1:])
171171
if err == flag.ErrHelp {
172+
helpShort()
172173
os.Exit(0)
173174
}
174175
if err != nil {
175-
tlog.Warn.Printf("You passed: %s", prettyArgs())
176-
tlog.Fatal.Printf("%v", err)
176+
tlog.Fatal.Printf("Invalid command line: %s. Try '%s -help'.", prettyArgs(), tlog.ProgramName)
177177
os.Exit(exitcodes.Usage)
178178
}
179179
// "-openssl" needs some post-processing
@@ -225,7 +225,7 @@ func parseCliOpts() (args argContainer) {
225225

226226
// prettyArgs pretty-prints the command-line arguments.
227227
func prettyArgs() string {
228-
pa := fmt.Sprintf("%q", os.Args[1:])
228+
pa := fmt.Sprintf("%v", os.Args)
229229
// Get rid of "[" and "]"
230230
pa = pa[1 : len(pa)-1]
231231
return pa

0 commit comments

Comments
 (0)