summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralabid <alabidan@gmail.com>2014-10-16 14:41:11 -0400
committeralabid <alabidan@gmail.com>2014-10-16 14:41:11 -0400
commit67c872973f73c62da7e61279d233bafef6bce106 (patch)
tree491ca17cf5cc5273efa279b42c1a8032e60fbeae
parentbc553b302d0b3ed9066a9e807913abfea2bce96b (diff)
downloadmongo-67c872973f73c62da7e61279d233bafef6bce106.tar.gz
tool options: add option to force print help
Former-commit-id: 5fcac882fe77e24391a98c399c924d02c31f8776
-rw-r--r--bsondump/main/bsondump.go8
-rw-r--r--common/options/options.go4
-rw-r--r--mongodump/main/mongodump.go2
-rw-r--r--mongoexport/main/mongoexport.go2
-rw-r--r--mongofiles/main/mongofiles.go13
-rw-r--r--mongoimport/main/mongoimport.go2
-rw-r--r--mongooplog/main/mongooplog.go2
-rw-r--r--mongorestore/main/mongorestore.go2
-rw-r--r--mongostat/main/mongostat.go6
-rw-r--r--mongotop/main/mongotop.go2
10 files changed, 20 insertions, 23 deletions
diff --git a/bsondump/main/bsondump.go b/bsondump/main/bsondump.go
index db9218c3c5c..b413c9480e9 100644
--- a/bsondump/main/bsondump.go
+++ b/bsondump/main/bsondump.go
@@ -22,7 +22,7 @@ func main() {
}
// print help, if specified
- if opts.PrintHelp() {
+ if opts.PrintHelp(false) {
return
}
@@ -34,17 +34,17 @@ func main() {
// pull out the filename
filename := ""
if len(extra) == 0 {
- opts.PrintHelp()
+ opts.PrintHelp(true)
return
} else if len(extra) > 1 {
fmt.Fprintln(os.Stderr, "Too many positional operators.")
- opts.PrintHelp()
+ opts.PrintHelp(true)
os.Exit(1)
} else {
filename = extra[0]
if filename == "" {
fmt.Fprintln(os.Stderr, "Filename must not be blank.")
- opts.PrintHelp()
+ opts.PrintHelp(true)
os.Exit(1)
}
}
diff --git a/common/options/options.go b/common/options/options.go
index 996f8dd3585..f67d004ae82 100644
--- a/common/options/options.go
+++ b/common/options/options.go
@@ -129,8 +129,8 @@ func New(appName, usageStr string) *ToolOptions {
// Print the usage message for the tool to stdout. Returns whether or not the
// help flag is specified.
-func (self *ToolOptions) PrintHelp() bool {
- if self.Help {
+func (self *ToolOptions) PrintHelp(force bool) bool {
+ if self.Help || force {
self.parser.WriteHelp(os.Stdout)
}
return self.Help
diff --git a/mongodump/main/mongodump.go b/mongodump/main/mongodump.go
index c1423e03628..44103611582 100644
--- a/mongodump/main/mongodump.go
+++ b/mongodump/main/mongodump.go
@@ -27,7 +27,7 @@ func main() {
}
// print help, if specified
- if opts.PrintHelp() {
+ if opts.PrintHelp(false) {
return
}
diff --git a/mongoexport/main/mongoexport.go b/mongoexport/main/mongoexport.go
index c4328bc1bb1..0827f33083e 100644
--- a/mongoexport/main/mongoexport.go
+++ b/mongoexport/main/mongoexport.go
@@ -32,7 +32,7 @@ func main() {
log.SetVerbosity(opts.Verbosity)
// print help, if specified
- if opts.PrintHelp() {
+ if opts.PrintHelp(false) {
return
}
diff --git a/mongofiles/main/mongofiles.go b/mongofiles/main/mongofiles.go
index 47f17c7f534..6de79a93e97 100644
--- a/mongofiles/main/mongofiles.go
+++ b/mongofiles/main/mongofiles.go
@@ -24,11 +24,6 @@ const (
`
)
-func printHelpAndExit() {
- fmt.Println("try 'mongofiles --help' for more information")
- os.Exit(1)
-}
-
func main() {
// initialize command-line opts
@@ -40,11 +35,12 @@ func main() {
args, err := opts.Parse()
if err != nil {
log.Logf(0, "error parsing command line options: %v", err)
- printHelpAndExit()
+ opts.PrintHelp(true)
+ os.Exit(1)
}
// print help, if specified
- if opts.PrintHelp() {
+ if opts.PrintHelp(false) {
return
}
@@ -58,7 +54,8 @@ func main() {
fileName, err := mongofiles.ValidateCommand(args)
if err != nil {
log.Logf(0, "error: %v", err)
- printHelpAndExit()
+ opts.PrintHelp(true)
+ os.Exit(1)
}
// create a session provider to connect to the db
diff --git a/mongoimport/main/mongoimport.go b/mongoimport/main/mongoimport.go
index 5b1c72e7afe..40cd09218bc 100644
--- a/mongoimport/main/mongoimport.go
+++ b/mongoimport/main/mongoimport.go
@@ -31,7 +31,7 @@ func main() {
log.SetVerbosity(opts.Verbosity)
// print help, if specified
- if opts.PrintHelp() {
+ if opts.PrintHelp(false) {
return
}
diff --git a/mongooplog/main/mongooplog.go b/mongooplog/main/mongooplog.go
index 601b58fd63a..1b2dcf8c0ea 100644
--- a/mongooplog/main/mongooplog.go
+++ b/mongooplog/main/mongooplog.go
@@ -28,7 +28,7 @@ func main() {
}
// print help, if specified
- if opts.PrintHelp() {
+ if opts.PrintHelp(false) {
return
}
diff --git a/mongorestore/main/mongorestore.go b/mongorestore/main/mongorestore.go
index 862de88cdde..a13d6839d41 100644
--- a/mongorestore/main/mongorestore.go
+++ b/mongorestore/main/mongorestore.go
@@ -27,7 +27,7 @@ func main() {
}
// print help or version info, if specified
- if opts.PrintHelp() {
+ if opts.PrintHelp(false) {
return
}
if opts.PrintVersion() {
diff --git a/mongostat/main/mongostat.go b/mongostat/main/mongostat.go
index 9263b52bb34..27622e35fc6 100644
--- a/mongostat/main/mongostat.go
+++ b/mongostat/main/mongostat.go
@@ -22,7 +22,7 @@ func main() {
extra, err := opts.Parse()
if err != nil {
fmt.Fprintf(os.Stderr, "Invalid options: %v\n", err)
- opts.PrintHelp()
+ opts.PrintHelp(true)
util.ExitFail()
return
}
@@ -31,7 +31,7 @@ func main() {
if len(extra) > 0 {
if len(extra) != 1 {
fmt.Fprintf(os.Stderr, "Too many positional operators\n")
- opts.PrintHelp()
+ opts.PrintHelp(true)
util.ExitFail()
return
}
@@ -49,7 +49,7 @@ func main() {
}
// print help, if specified
- if opts.PrintHelp() {
+ if opts.PrintHelp(false) {
return
}
diff --git a/mongotop/main/mongotop.go b/mongotop/main/mongotop.go
index e1e5406fba5..c40c0abad37 100644
--- a/mongotop/main/mongotop.go
+++ b/mongotop/main/mongotop.go
@@ -32,7 +32,7 @@ func main() {
}
// print help, if specified
- if opts.PrintHelp() {
+ if opts.PrintHelp(false) {
return
}