main: print clear error message if CIPHERDIR is missing

Getting just the help text in response to

	gocryptfs -info -config external.config

is confusing: https://github.com/rfjakob/gocryptfs/issues/157
This commit is contained in:
Jakob Unterwurzacher 2017-11-15 20:30:21 +01:00
parent e36a0ebf18
commit 1b0426bcb2
2 changed files with 17 additions and 10 deletions

View File

@ -20,7 +20,7 @@ func info(filename string) {
// Read from disk // Read from disk
js, err := ioutil.ReadFile(filename) js, err := ioutil.ReadFile(filename)
if err != nil { if err != nil {
tlog.Fatal.Printf("info: ReadFile: %#v\n", err) tlog.Fatal.Printf("Reading config file failed: %v", err)
os.Exit(exitcodes.LoadConf) os.Exit(exitcodes.LoadConf)
} }
// Unmarshal // Unmarshal

25
main.go
View File

@ -143,18 +143,25 @@ func main() {
tlog.Warn.Wpanic = true tlog.Warn.Wpanic = true
tlog.Debug.Printf("Panicing on warnings") tlog.Debug.Printf("Panicing on warnings")
} }
// Every operation below requires CIPHERDIR. Check that we have it. // Every operation below requires CIPHERDIR. Exit if we don't have it.
if flagSet.NArg() >= 1 { if flagSet.NArg() == 0 {
args.cipherdir, _ = filepath.Abs(flagSet.Arg(0)) if flagSet.NFlag() == 0 {
err = checkDir(args.cipherdir) // Naked call to "gocryptfs". Just print the help text.
if err != nil { helpShort()
tlog.Fatal.Printf("Invalid cipherdir: %v", err) } else {
os.Exit(exitcodes.CipherDir) // The user has passed some flags, but CIPHERDIR is missing. State
// what is wrong.
tlog.Fatal.Printf("CIPHERDIR argument is missing")
} }
} else {
helpShort()
os.Exit(exitcodes.Usage) os.Exit(exitcodes.Usage)
} }
// Check that CIPHERDIR exists
args.cipherdir, _ = filepath.Abs(flagSet.Arg(0))
err = checkDir(args.cipherdir)
if err != nil {
tlog.Fatal.Printf("Invalid cipherdir: %v", err)
os.Exit(exitcodes.CipherDir)
}
// "-q" // "-q"
if args.quiet { if args.quiet {
tlog.Info.Enabled = false tlog.Info.Enabled = false