summaryrefslogtreecommitdiff
path: root/common/options/options.go
diff options
context:
space:
mode:
Diffstat (limited to 'common/options/options.go')
-rw-r--r--common/options/options.go34
1 files changed, 21 insertions, 13 deletions
diff --git a/common/options/options.go b/common/options/options.go
index 49ab99e354d..b6866f9ef8c 100644
--- a/common/options/options.go
+++ b/common/options/options.go
@@ -3,9 +3,10 @@
package options
import (
- "fmt"
"github.com/jessevdk/go-flags"
"github.com/mongodb/mongo-tools/common/log"
+
+ "fmt"
"os"
"regexp"
"runtime"
@@ -13,9 +14,9 @@ import (
"strings"
)
-const (
- VersionStr = "3.3.3-pre-"
-)
+const VersionStr = "3.3.3-pre-"
+
+const DefaultDialTimeoutSeconds = 3
// Gitspec that the tool was built with. Needs to be set using -ldflags
var (
@@ -66,8 +67,9 @@ type HiddenOptions struct {
// Deprecated flag for csv writing in mongoexport
CSVOutputType bool
- TempUsersColl *string
- TempRolesColl *string
+ TempUsersColl *string
+ TempRolesColl *string
+ DialTimeoutSeconds *int
}
type Namespace struct {
@@ -150,8 +152,10 @@ func parseVal(val string) int {
// Ask for a new instance of tool options
func New(appName, usageStr string, enabled EnabledOptions) *ToolOptions {
+ var timeout = DefaultDialTimeoutSeconds
hiddenOpts := &HiddenOptions{
- BulkBufferSize: 10000,
+ BulkBufferSize: 10000,
+ DialTimeoutSeconds: &timeout,
}
opts := &ToolOptions{
@@ -186,9 +190,7 @@ func New(appName, usageStr string, enabled EnabledOptions) *ToolOptions {
}
}
- opts.parser.UnknownOptionHandler = func(option string, arg flags.SplitArgument, args []string) ([]string, error) {
- return parseHiddenOption(hiddenOpts, option, arg, args)
- }
+ opts.parser.UnknownOptionHandler = hiddenOpts.parseHiddenOption
if _, err := opts.parser.AddGroup("general options", "", opts.General); err != nil {
panic(fmt.Errorf("couldn't register general options: %v", err))
@@ -294,10 +296,10 @@ func (o *ToolOptions) Parse() ([]string, error) {
return o.parser.Parse()
}
-func parseHiddenOption(opts *HiddenOptions, option string, arg flags.SplitArgument, args []string) ([]string, error) {
+func (opts *HiddenOptions) parseHiddenOption(option string, arg flags.SplitArgument, args []string) ([]string, error) {
if option == "dbpath" || option == "directoryperdb" || option == "journal" {
- return args, fmt.Errorf(`--dbpath and related flags are not supported in 3.0 tools.
-See http://dochub.mongodb.org/core/tools-dbpath-deprecated for more information`)
+ return args, fmt.Errorf("--dbpath and related flags are not supported in 3.0 tools.\n" +
+ "See http://dochub.mongodb.org/core/tools-dbpath-deprecated for more information")
}
if option == "csv" {
@@ -338,6 +340,12 @@ See http://dochub.mongodb.org/core/tools-dbpath-deprecated for more information`
opts.BulkBufferSize = optionValue
case "numDecodingWorkers":
opts.NumDecodingWorkers = optionValue
+ case "dialTimeout":
+ if optionValue >= 0 {
+ opts.DialTimeoutSeconds = &optionValue
+ } else {
+ return args, fmt.Errorf("invalid negative value for --dialTimeout")
+ }
default:
return args, fmt.Errorf(`unknown option "%v"`, option)
}