summaryrefslogtreecommitdiff
path: root/src/mongo/tools/tool.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/tools/tool.h')
-rw-r--r--src/mongo/tools/tool.h111
1 files changed, 28 insertions, 83 deletions
diff --git a/src/mongo/tools/tool.h b/src/mongo/tools/tool.h
index 2e7b0823d62..e5b627845bb 100644
--- a/src/mongo/tools/tool.h
+++ b/src/mongo/tools/tool.h
@@ -12,6 +12,18 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects
+ * for all of the code used other than as permitted herein. If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so. If you do not
+ * wish to do so, delete this exception statement from your version. If you
+ * delete this exception statement from all source files in the program,
+ * then also delete it in the license file.
*/
// Tool.h
@@ -20,14 +32,15 @@
#include <string>
-#include <boost/program_options.hpp>
-
#if defined(_WIN32)
#include <io.h>
#endif
-#include "db/instance.h"
-#include "db/matcher.h"
+#include "mongo/db/instance.h"
+#include "mongo/db/matcher.h"
+#include "mongo/tools/tool_logger.h"
+#include "mongo/tools/tool_options.h"
+#include "mongo/util/options_parser/environment.h"
using std::string;
@@ -35,122 +48,50 @@ namespace mongo {
class Tool {
public:
- enum DBAccess {
- NONE = 0 ,
- REMOTE_SERVER = 1 << 1 ,
- LOCAL_SERVER = 1 << 2 ,
- SPECIFY_DBCOL = 1 << 3 ,
- ALL = REMOTE_SERVER | LOCAL_SERVER | SPECIFY_DBCOL
- };
-
- Tool( string name , DBAccess access=ALL, string defaultDB="test" ,
- string defaultCollection="", bool usesstdout=true);
+ Tool();
virtual ~Tool();
- int main( int argc , char ** argv );
-
- boost::program_options::options_description_easy_init add_options() {
- return _options->add_options();
- }
- boost::program_options::options_description_easy_init add_hidden_options() {
- return _hidden_options->add_options();
- }
- void addPositionArg( const char * name , int pos ) {
- _positonalOptions.add( name , pos );
- }
+ static auto_ptr<Tool> (*createInstance)();
- string getParam( string name , string def="" ) {
- if ( _params.count( name ) )
- return _params[name.c_str()].as<string>();
- return def;
- }
- int getParam( string name , int def ) {
- if ( _params.count( name ) )
- return _params[name.c_str()].as<int>();
- return def;
- }
- bool hasParam( string name ) {
- return _params.count( name );
- }
+ int main( int argc , char ** argv, char ** envp );
string getNS() {
- if ( _coll.size() == 0 ) {
+ if (toolGlobalParams.coll.size() == 0) {
cerr << "no collection specified!" << endl;
throw -1;
}
- return _db + "." + _coll;
+ return toolGlobalParams.db + "." + toolGlobalParams.coll;
}
string getAuthenticationDatabase();
- void useStandardOutput( bool mode ) {
- _usesstdout = mode;
- }
-
bool isMaster();
bool isMongos();
-
- virtual void preSetup() {}
virtual int run() = 0;
- virtual void printHelp(ostream &out);
-
- virtual void printExtraHelp( ostream & out ) {}
- virtual void printExtraHelpAfter( ostream & out ) {}
-
- virtual void printVersion(ostream &out);
+ virtual void printHelp(ostream &out) = 0;
protected:
mongo::DBClientBase &conn( bool slaveIfPaired = false );
- string _name;
-
- string _db;
- string _coll;
- string _fileName;
-
- string _username;
- string _password;
- string _authenticationDatabase;
- string _authenticationMechanism;
-
- bool _usesstdout;
- bool _noconnection;
bool _autoreconnect;
- void addFieldOptions();
- void needFields();
-
- vector<string> _fields;
- BSONObj _fieldsObj;
-
-
- string _host;
-
protected:
mongo::DBClientBase * _conn;
mongo::DBClientBase * _slaveConn;
- bool _paired;
-
- boost::program_options::options_description * _options;
- boost::program_options::options_description * _hidden_options;
- boost::program_options::positional_options_description _positonalOptions;
-
- boost::program_options::variables_map _params;
private:
void auth();
};
class BSONTool : public Tool {
- bool _objcheck;
auto_ptr<Matcher> _matcher;
public:
- BSONTool( const char * name , DBAccess access=ALL, bool objcheck = true );
+ BSONTool();
virtual int doRun() = 0;
virtual void gotObject( const BSONObj& obj ) = 0;
@@ -162,3 +103,7 @@ namespace mongo {
};
}
+
+#define REGISTER_MONGO_TOOL(TYPENAME) \
+ auto_ptr<Tool> createInstanceOfThisTool() {return auto_ptr<Tool>(new TYPENAME());} \
+ auto_ptr<Tool> (*Tool::createInstance)() = createInstanceOfThisTool;