summaryrefslogtreecommitdiff
path: root/cli_args.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-10-09 19:38:49 +0200
committerJakob Unterwurzacher2016-10-09 20:05:54 +0200
commit9cf3ced0ce95495cabd8f4e7055d1c98f42363c9 (patch)
treeeec3bede62b9c6d0a72f13cca3609906336b1401 /cli_args.go
parent25a8802403de157bdfc39b7860ea4e3ee2b1d8ee (diff)
main: also accept options at the end via "-o"
For compatability with mount(1), options are also accepted as "-o COMMA-SEPARATED-OPTIONS" at the end of the command line. For example, "-o q,zerokey" is equivalent to "-q -zerokey".
Diffstat (limited to 'cli_args.go')
-rw-r--r--cli_args.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/cli_args.go b/cli_args.go
index 94363d0..0db5ba6 100644
--- a/cli_args.go
+++ b/cli_args.go
@@ -4,6 +4,7 @@ import (
"flag"
"os"
"strconv"
+ "strings"
"github.com/rfjakob/gocryptfs/internal/configfile"
"github.com/rfjakob/gocryptfs/internal/prefer_openssl"
@@ -27,8 +28,32 @@ type argContainer struct {
var flagSet *flag.FlagSet
+// prefixOArgs transform options passed via "-o foo,bar" into regular options
+// like "-foo -bar" and prefixes them to the command line.
+func prefixOArgs(osArgs []string) []string {
+ l := len(osArgs)
+ // Need at least 3, example: gocryptfs -o foo,bar
+ if l < 3 {
+ return osArgs
+ }
+ if osArgs[l-2] != "-o" {
+ return osArgs
+ }
+ oOpts := strings.Split(osArgs[l-1], ",")
+ osArgs = osArgs[:l-2]
+ newArgs := []string{osArgs[0]}
+ // Add options from "-o"
+ for _, a := range oOpts {
+ newArgs = append(newArgs, "-"+a)
+ }
+ newArgs = append(newArgs, osArgs[1:]...)
+ return newArgs
+}
+
// parseCliOpts - parse command line options (i.e. arguments that start with "-")
func parseCliOpts() (args argContainer) {
+ os.Args = prefixOArgs(os.Args)
+
var err error
var opensslAuto string