aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2018-04-01 14:25:10 +0200
committerJakob Unterwurzacher2018-04-01 14:25:10 +0200
commit8fcd39a3b08f956edc0939c87b089b4dbb60afd6 (patch)
tree5c248ef6d83c19e6b70c53e34c049ac7182a6807 /main.go
parent85056def909c994b66c40763f6d6c2d41c7a61d0 (diff)
main: add "-fsck" flag
The fsck operation is not yet implemented, this commits just adds the flag and improves cli flag handling.
Diffstat (limited to 'main.go')
-rw-r--r--main.go47
1 files changed, 24 insertions, 23 deletions
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
}