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".
This commit is contained in:
Jakob Unterwurzacher 2017-05-30 17:59:13 +02:00
parent 9a217ce786
commit df2f4b1c40
3 changed files with 63 additions and 19 deletions

View File

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

53
help.go Normal file
View File

@ -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")
}

22
main.go
View File

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