diff options
Diffstat (limited to 'cli_args.go')
-rw-r--r-- | cli_args.go | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/cli_args.go b/cli_args.go index 2f0c936..6253c14 100644 --- a/cli_args.go +++ b/cli_args.go @@ -42,16 +42,16 @@ 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. // Testcases in TestPrefixOArgs(). -func prefixOArgs(osArgs []string) []string { +func prefixOArgs(osArgs []string) ([]string, error) { // Need at least 3, example: gocryptfs -o foo,bar // ^ 0 ^ 1 ^ 2 if len(osArgs) < 3 { - return osArgs + return osArgs, nil } // Passing "--" disables "-o" parsing. Ignore element 0 (program name). for _, v := range osArgs[1:] { if v == "--" { - return osArgs + return osArgs, nil } } // Find and extract "-o foo,bar" @@ -60,8 +60,7 @@ func prefixOArgs(osArgs []string) []string { if osArgs[i] == "-o" { // Last argument? if i+1 >= len(osArgs) { - tlog.Fatal.Printf("The \"-o\" option requires an argument") - os.Exit(exitcodes.Usage) + return nil, fmt.Errorf("The \"-o\" option requires an argument") } oOpts = strings.Split(osArgs[i+1], ",") // Skip over the arguments to "-o" @@ -87,16 +86,20 @@ func prefixOArgs(osArgs []string) []string { } // Add other arguments newArgs = append(newArgs, otherArgs...) - return newArgs + return newArgs, nil } // 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 + os.Args, err = prefixOArgs(os.Args) + if err != nil { + tlog.Fatal.Println(err) + os.Exit(exitcodes.Usage) + } + flagSet = flag.NewFlagSet(tlog.ProgramName, flag.ContinueOnError) flagSet.Usage = helpShort flagSet.BoolVar(&args.debug, "d", false, "") |