0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 17:10:48 +01:00
mongodb/tools/Tool.cpp

77 lines
1.9 KiB
C++
Raw Normal View History

2009-01-27 21:16:09 +01:00
// Tool.cpp
#include "Tool.h"
#include <iostream>
#include <boost/filesystem/operations.hpp>
namespace mongo {
DBClientBase *createDirectClient() {
cout << "no direct client available" << endl;
assert( false );
return 0;
}
} // namespace mongo
2009-01-27 21:16:09 +01:00
using namespace std;
using namespace mongo;
namespace po = boost::program_options;
mongo::Tool::Tool( string name , string defaultDB , string defaultCollection ) :
_name( name ) , _db( defaultDB ) , _coll( defaultCollection ){
_options = new po::options_description( name + " options" );
_options->add_options()
("help","produce help message")
("host,h",po::value<string>(), "mongo host to connect to" )
("db,d",po::value<string>(), "database to use" )
("collection,c",po::value<string>(), "collection to use (some commands)" )
;
}
mongo::Tool::~Tool(){
delete( _options );
}
void mongo::Tool::printExtraHelp( ostream & out ){
}
2009-01-27 21:16:09 +01:00
int mongo::Tool::main( int argc , char ** argv ){
boost::filesystem::path::default_name_check( boost::filesystem::no_check );
2009-01-28 03:37:56 +01:00
po::store( po::command_line_parser( argc , argv ).
options( *_options ).
positional( _positonalOptions ).run() , _params );
2009-01-27 21:16:09 +01:00
po::notify( _params );
if ( _params.count( "help" ) ){
_options->print( cerr );
printExtraHelp( cerr );
2009-01-27 21:16:09 +01:00
return 0;
}
const char * host = "127.0.0.1";
if ( _params.count( "host" ) )
host = _params["host"].as<string>().c_str();
string errmsg;
if ( ! _conn.connect( host , errmsg ) ){
cerr << "couldn't connect to [" << host << "] " << errmsg << endl;
return -1;
}
2009-05-18 20:45:37 +02:00
cerr << "connected to: " << host << endl;
2009-01-27 21:16:09 +01:00
if ( _params.count( "db" ) )
_db = _params["db"].as<string>();
if ( _params.count( "collection" ) )
_coll = _params["collection"].as<string>();
return run();
2009-01-27 21:16:09 +01:00
}