0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

minor: whitespace

This commit is contained in:
Mike Dirolf 2009-06-25 16:11:38 -04:00
parent 78cf591a96
commit efe8911ecc
3 changed files with 28 additions and 28 deletions

View File

@ -13,9 +13,9 @@ using namespace mongo;
namespace po = boost::program_options;
mongo::Tool::Tool( string name , string defaultDB , string defaultCollection ) :
mongo::Tool::Tool( string name , string defaultDB , string defaultCollection ) :
_name( name ) , _db( defaultDB ) , _coll( defaultCollection ), _useDirect() {
_options = new po::options_description( name + " options" );
_options->add_options()
("help","produce help message")
@ -36,7 +36,7 @@ void mongo::Tool::printExtraHelp( ostream & out ){
int mongo::Tool::main( int argc , char ** argv ){
boost::filesystem::path::default_name_check( boost::filesystem::no_check );
po::store( po::command_line_parser( argc , argv ).
options( *_options ).
positional( _positonalOptions ).run() , _params );
@ -53,13 +53,13 @@ int mongo::Tool::main( int argc , char ** argv ){
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;
}
cerr << "connected to: " << host << endl;
} else {
_useDirect = true;
@ -68,10 +68,10 @@ int mongo::Tool::main( int argc , char ** argv ){
mongo::acquirePathLock();
theFileAllocator().start();
}
if ( _params.count( "db" ) )
_db = _params["db"].as<string>();
if ( _params.count( "collection" ) )
_coll = _params["collection"].as<string>();

View File

@ -16,21 +16,21 @@
using std::string;
namespace mongo {
class Tool {
public:
Tool( string name , string defaultDB="test" , string defaultCollection="");
virtual ~Tool();
int main( int argc , char ** argv );
boost::program_options::options_description_easy_init add_options(){
return _options->add_options();
}
void addPositionArg( const char * name , int pos ){
_positonalOptions.add( name , pos );
}
string getParam( string name , string def="" ){
if ( _params.count( name ) )
return _params[name.c_str()].as<string>();
@ -49,9 +49,9 @@ namespace mongo {
}
virtual int run() = 0;
virtual void printExtraHelp( ostream & out );
protected:
string _name;
@ -59,7 +59,7 @@ namespace mongo {
string _coll;
mongo::DBClientBase &conn() { return _useDirect ? (mongo::DBClientBase&)_direct : (mongo::DBClientBase&)_conn; };
private:
mongo::DBClientConnection _conn;
mongo::DBDirectClient _direct;
@ -68,7 +68,7 @@ namespace mongo {
boost::program_options::positional_options_description _positonalOptions;
boost::program_options::variables_map _params;
};
}

View File

@ -42,7 +42,7 @@ public:
("out,o", po::value<string>(), "output file; if not specified, stdout is used")
;
}
int run(){
const string ns = getNS();
const bool csv = hasParam( "csv" );
@ -51,37 +51,37 @@ public:
if ( hasParam( "out" ) )
outPtr = new ofstream( outfile.c_str() );
ostream &out = *outPtr;
BSONObj * fieldsToReturn = 0;
BSONObj realFieldsToReturn;
vector<string> fields;
if ( hasParam( "fields" ) ){
BSONObjBuilder b;
pcrecpp::StringPiece input( getParam( "fields" ) );
string f;
pcrecpp::RE re("(\\w+),?" );
while ( re.Consume( &input, &f ) ){
fields.push_back( f );
b.append( f.c_str() , 1 );
}
realFieldsToReturn = b.obj();
fieldsToReturn = &realFieldsToReturn;
}
if ( csv && fields.size() == 0 ){
cerr << "csv mode requires a field list" << endl;
return -1;
}
auto_ptr<DBClientCursor> cursor = conn().query( ns.c_str() , getParam( "query" , "" ) , 0 , 0 , fieldsToReturn , Option_SlaveOk );
if ( csv ){
for ( vector<string>::iterator i=fields.begin(); i != fields.end(); i++ ){
if ( i != fields.begin() )
@ -90,7 +90,7 @@ public:
}
out << endl;
}
while ( cursor->more() ) {
BSONObj obj = cursor->next();
if ( csv ){
@ -100,7 +100,7 @@ public:
const BSONElement & e = obj[i->c_str()];
if ( ! e.eoo() )
out << e.jsonString( TenGen , false );
}
}
out << endl;
}
else {