diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/bsondump.cpp | 2 | ||||
-rw-r--r-- | tools/dump.cpp | 2 | ||||
-rw-r--r-- | tools/stat.cpp | 2 | ||||
-rw-r--r-- | tools/tool.cpp | 29 | ||||
-rw-r--r-- | tools/tool.h | 12 |
5 files changed, 30 insertions, 17 deletions
diff --git a/tools/bsondump.cpp b/tools/bsondump.cpp index 699e099d43c..5b921e4e0d7 100644 --- a/tools/bsondump.cpp +++ b/tools/bsondump.cpp @@ -36,7 +36,7 @@ class BSONDump : public BSONTool { public: - BSONDump() : BSONTool( "bsondump" ){ + BSONDump() : BSONTool( "bsondump", NONE ){ add_options() ("type" , po::value<string>()->default_value("json") , "type of output: json,debug" ) ; diff --git a/tools/dump.cpp b/tools/dump.cpp index 8f4169f76a5..c8d777e3bf2 100644 --- a/tools/dump.cpp +++ b/tools/dump.cpp @@ -28,7 +28,7 @@ namespace po = boost::program_options; class Dump : public Tool { public: - Dump() : Tool( "dump" , true , "*" , "*" , false ){ + Dump() : Tool( "dump" , ALL , "*" , "*" , false ){ add_options() ("out,o", po::value<string>()->default_value("dump"), "output directory or stdout") ("query,q", po::value<string>() , "json query" ) diff --git a/tools/stat.cpp b/tools/stat.cpp index d94cf8d92a4..9bc2956f339 100644 --- a/tools/stat.cpp +++ b/tools/stat.cpp @@ -35,7 +35,7 @@ namespace mongo { class Stat : public Tool { public: - Stat() : Tool( "stat" , false , "admin" ){ + Stat() : Tool( "stat" , NO_LOCAL , "admin" ){ _sleep = 1; _rowNum = 0; _showHeaders = true; diff --git a/tools/tool.cpp b/tools/tool.cpp index dbb3de140e9..5887d2ea810 100644 --- a/tools/tool.cpp +++ b/tools/tool.cpp @@ -35,7 +35,7 @@ namespace mongo { CmdLine cmdLine; - Tool::Tool( string name , bool localDBAllowed , string defaultDB , + Tool::Tool( string name , DBAccess access , string defaultDB , string defaultCollection , bool usesstdout ) : _name( name ) , _db( defaultDB ) , _coll( defaultCollection ) , _usesstdout(usesstdout), _noconnection(false), _autoreconnect(false), _conn(0), _paired(false) { @@ -44,15 +44,21 @@ namespace mongo { _options->add_options() ("help","produce help message") ("verbose,v", "be more verbose (include multiple times for more verbosity e.g. -vvvvv)") - ("host,h",po::value<string>(), "mongo host to connect to (\"left,right\" for pairs)" ) - ("port",po::value<string>(), "server port. Can also use --host hostname:port" ) - ("db,d",po::value<string>(), "database to use" ) - ("collection,c",po::value<string>(), "collection to use (some commands)" ) - ("username,u",po::value<string>(), "username" ) - ("password,p", new PasswordValue( &_password ), "password" ) - ("ipv6", "enable IPv6 support (disabled by default)") ; - if ( localDBAllowed ) + + if ( access == ALL || access == NO_LOCAL){ + _options->add_options() + ("host,h",po::value<string>(), "mongo host to connect to (\"left,right\" for pairs)" ) + ("port",po::value<string>(), "server port. Can also use --host hostname:port" ) + ("db,d",po::value<string>(), "database to use" ) + ("collection,c",po::value<string>(), "collection to use (some commands)" ) + ("username,u",po::value<string>(), "username" ) + ("password,p", new PasswordValue( &_password ), "password" ) + ("ipv6", "enable IPv6 support (disabled by default)") + ; + } + + if ( access == ALL ) { _options->add_options() ("dbpath",po::value<string>(), "directly access mongod database " "files in the given path, instead of connecting to a mongod " @@ -60,6 +66,7 @@ namespace mongo { "used if a mongod is currently accessing the same path" ) ("directoryperdb", "if dbpath specified, each db is in a separate directory" ) ; + } _hidden_options = new po::options_description( name + " hidden options" ); @@ -307,8 +314,8 @@ namespace mongo { throw UserException( 9997 , (string)"auth failed: " + errmsg ); } - BSONTool::BSONTool( const char * name , bool objcheck ) - : Tool( name , true , "" , "" ) , _objcheck( objcheck ){ + BSONTool::BSONTool( const char * name, DBAccess access , bool objcheck ) + : Tool( name , access , "" , "" ) , _objcheck( objcheck ){ add_options() ("objcheck" , "validate object before inserting" ) diff --git a/tools/tool.h b/tools/tool.h index 900c02f2205..fec26a73242 100644 --- a/tools/tool.h +++ b/tools/tool.h @@ -35,8 +35,14 @@ namespace mongo { class Tool { public: - Tool( string name , bool localDBAllowed=true, string defaultDB="test" , - string defaultCollection="", bool usesstdout=true ); + enum DBAccess{ + NONE, + ALL, + NO_LOCAL + }; + + Tool( string name , DBAccess access=ALL, string defaultDB="test" , + string defaultCollection="", bool usesstdout=true); virtual ~Tool(); int main( int argc , char ** argv ); @@ -126,7 +132,7 @@ namespace mongo { auto_ptr<Matcher> _matcher; public: - BSONTool( const char * name , bool objcheck = false ); + BSONTool( const char * name , DBAccess access=ALL, bool objcheck = false ); virtual int doRun() = 0; virtual void gotObject( const BSONObj& obj ) = 0; |