diff options
| author | Jakob Unterwurzacher | 2017-05-30 17:59:13 +0200 | 
|---|---|---|
| committer | Jakob Unterwurzacher | 2017-05-30 17:59:13 +0200 | 
| commit | df2f4b1c40dec4a9996fd07cc7db1f2c82afbb7c (patch) | |
| tree | 6d0ec1e3915f98a8318ffbfafa78cef9ece93b87 | |
| parent | 9a217ce786581ee7ec18b27e46f0096763c85f9e (diff) | |
main: add short help text
We have accumulated so many options over time that they
no longer fit on the screen.
Display only a useful subset of options to the user unless
they pass "-hh".
| -rw-r--r-- | cli_args.go | 7 | ||||
| -rw-r--r-- | help.go | 53 | ||||
| -rw-r--r-- | main.go | 22 | 
3 files changed, 63 insertions, 19 deletions
| diff --git a/cli_args.go b/cli_args.go index be6d688..eb844e1 100644 --- a/cli_args.go +++ b/cli_args.go @@ -20,7 +20,7 @@ type argContainer struct {  	debug, init, zerokey, fusedebug, openssl, passwd, fg, version,  	plaintextnames, quiet, nosyslog, wpanic,  	longnames, allow_other, ro, reverse, aessiv, nonempty, raw64, -	noprealloc, speed, hkdf, serialize_reads, forcedecode bool +	noprealloc, speed, hkdf, serialize_reads, forcedecode, hh bool  	masterkey, mountpoint, cipherdir, cpuprofile, extpass,  	memprofile, ko, passfile, ctlsock, fsname string  	// Configuration file name override @@ -94,7 +94,7 @@ func parseCliOpts() (args argContainer) {  	var opensslAuto string  	flagSet = flag.NewFlagSet(tlog.ProgramName, flag.ContinueOnError) -	flagSet.Usage = usageText +	flagSet.Usage = helpShort  	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") @@ -125,6 +125,7 @@ func parseCliOpts() (args argContainer) {  	flagSet.BoolVar(&args.serialize_reads, "serialize_reads", false, "Try to serialize read operations")  	flagSet.BoolVar(&args.forcedecode, "forcedecode", false, "Force decode of files even if integrity check fails."+  		" Requires gocryptfs to be compiled with openssl support and implies -openssl true") +	flagSet.BoolVar(&args.hh, "hh", false, "Show this long help text")  	flagSet.StringVar(&args.masterkey, "masterkey", "", "Mount with explicit master key")  	flagSet.StringVar(&args.cpuprofile, "cpuprofile", "", "Write cpu profile to specified file")  	flagSet.StringVar(&args.memprofile, "memprofile", "", "Write memory profile to specified file") @@ -145,7 +146,7 @@ func parseCliOpts() (args argContainer) {  	flagSet.BoolVar(&dummyBool, "nosuid", false, ignoreText)  	flagSet.BoolVar(&dummyBool, "nodev", false, ignoreText)  	var dummyString string -	flagSet.StringVar(&dummyString, "o", "", "For compatibility, all options can be also passed as a comma-separated list to -o.") +	flagSet.StringVar(&dummyString, "o", "", "For compatibility with mount(1), options can be also passed as a comma-separated list to -o on the end.")  	// Actual parsing  	err = flagSet.Parse(os.Args[1:])  	if err == flag.ErrHelp { @@ -0,0 +1,53 @@ +package main + +import ( +	"fmt" + +	"github.com/rfjakob/gocryptfs/internal/tlog" +) + +const tUsage = "" + +	"Usage: " + tlog.ProgramName + " -init|-passwd [OPTIONS] CIPHERDIR\n" + +	"  or   " + tlog.ProgramName + " [OPTIONS] CIPHERDIR MOUNTPOINT\n" + +// helpShort is what gets displayed when passed "-h" or on syntax error. +func helpShort() { +	printVersion() +	fmt.Printf("\n") +	fmt.Printf(tUsage) +	fmt.Printf(` +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 +  -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 +`) +} + +// helpLong gets only displayed on "-hh" +func helpLong() { +	printVersion() +	fmt.Printf("\n") +	fmt.Printf(tUsage) +	fmt.Printf("\nOptions:\n") +	flagSet.PrintDefaults() +	fmt.Printf("  --\n    	Stop option parsing\n") +} @@ -31,21 +31,6 @@ var BuildTime = "0"  // raceDetector is set to true by race.go if we are compiled with "go build -race"  var raceDetector bool -func usageText() { -	printVersion() -	fmt.Printf(` -Usage: %s -init|-passwd [OPTIONS] CIPHERDIR -  or   %s [OPTIONS] CIPHERDIR MOUNTPOINT [-o COMMA-SEPARATED-OPTIONS] - -Options: -`, tlog.ProgramName, tlog.ProgramName) - -	flagSet.PrintDefaults() -	fmt.Print(`  -- -    	Stop option parsing -`) -} -  // loadConfig loads the config file "args.config", prompting the user for the password  func loadConfig(args *argContainer) (masterkey []byte, confFile *configfile.ConfFile, err error) {  	// Check if the file can be opened at all before prompting for a password @@ -145,6 +130,11 @@ func main() {  		printVersion()  		os.Exit(0)  	} +	// "-hh" +	if args.hh { +		helpLong() +		os.Exit(0) +	}  	// "-speed"  	if args.speed {  		speed.Run() @@ -163,7 +153,7 @@ func main() {  			os.Exit(exitcodes.CipherDir)  		}  	} else { -		usageText() +		helpShort()  		os.Exit(exitcodes.Usage)  	}  	// "-q" | 
