From 8fcd39a3b08f956edc0939c87b089b4dbb60afd6 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 1 Apr 2018 14:25:10 +0200 Subject: main: add "-fsck" flag The fsck operation is not yet implemented, this commits just adds the flag and improves cli flag handling. --- main.go | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index ea5efb3..ff137c4 100644 --- a/main.go +++ b/main.go @@ -246,45 +246,46 @@ func main() { tlog.Debug.Printf("OpenSSL enabled") } // Operation flags - if args.info && args.init || args.info && args.passwd || args.passwd && args.init { - tlog.Fatal.Printf("At most one of -info, -init, -passwd is allowed") + nOps := countOpFlags(&args) + if nOps == 0 { + // Default operation: mount. + if flagSet.NArg() != 2 { + prettyArgs := prettyArgs() + tlog.Info.Printf("Wrong number of arguments (have %d, want 2). You passed: %s", + flagSet.NArg(), prettyArgs) + tlog.Fatal.Printf("Usage: %s [OPTIONS] CIPHERDIR MOUNTPOINT [-o COMMA-SEPARATED-OPTIONS]", tlog.ProgramName) + os.Exit(exitcodes.Usage) + } + doMount(&args) + // Don't call os.Exit to give deferred functions a chance to run + return + } + if nOps > 1 { + tlog.Fatal.Printf("At most one of -info, -init, -passwd, -fsck is allowed") + os.Exit(exitcodes.Usage) + } + if flagSet.NArg() != 1 { + tlog.Fatal.Printf("The options -info, -init, -passwd, -fsck take exactly one argument, %d given", + flagSet.NArg()) os.Exit(exitcodes.Usage) } // "-info" if args.info { - if flagSet.NArg() > 1 { - tlog.Fatal.Printf("Usage: %s -info CIPHERDIR", tlog.ProgramName) - os.Exit(exitcodes.Usage) - } info(args.config) os.Exit(0) } // "-init" if args.init { - if flagSet.NArg() > 1 { - tlog.Fatal.Printf("Usage: %s -init [OPTIONS] CIPHERDIR", tlog.ProgramName) - os.Exit(exitcodes.Usage) - } initDir(&args) os.Exit(0) } // "-passwd" if args.passwd { - if flagSet.NArg() > 1 { - tlog.Fatal.Printf("Usage: %s -passwd [OPTIONS] CIPHERDIR", tlog.ProgramName) - os.Exit(exitcodes.Usage) - } changePassword(&args) os.Exit(0) } - // Default operation: mount. - if flagSet.NArg() != 2 { - prettyArgs := prettyArgs() - tlog.Info.Printf("Wrong number of arguments (have %d, want 2). You passed: %s", - flagSet.NArg(), prettyArgs) - tlog.Fatal.Printf("Usage: %s [OPTIONS] CIPHERDIR MOUNTPOINT [-o COMMA-SEPARATED-OPTIONS]", tlog.ProgramName) - os.Exit(exitcodes.Usage) + // "-fsck" + if args.fsck { + fsck(&args) } - doMount(&args) - // Don't call os.Exit to give deferred functions a chance to run } -- cgit v1.2.3