mirror of https://github.com/mongodb/mongo
add hidden_options to Tool.cpp - better help message for mongofiles
This commit is contained in:
parent
0bbc36fae3
commit
71f76d998c
|
|
@ -16,7 +16,7 @@ namespace po = boost::program_options;
|
|||
mongo::Tool::Tool( string name , string defaultDB , string defaultCollection ) :
|
||||
_name( name ) , _db( defaultDB ) , _coll( defaultCollection ) , _conn(0), _paired(false) {
|
||||
|
||||
_options = new po::options_description( name + " options" );
|
||||
_options = new po::options_description( "options" );
|
||||
_options->add_options()
|
||||
("help","produce help message")
|
||||
("host,h",po::value<string>(), "mongo host to connect to" )
|
||||
|
|
@ -28,10 +28,12 @@ mongo::Tool::Tool( string name , string defaultDB , string defaultCollection ) :
|
|||
("verbose,v", "be more verbose (include multiple times for more verbosity e.g. -vvvvv)")
|
||||
;
|
||||
|
||||
_hidden_options = new po::options_description( name + " hidden options" );
|
||||
}
|
||||
|
||||
mongo::Tool::~Tool(){
|
||||
delete( _options );
|
||||
delete( _hidden_options );
|
||||
if ( _conn )
|
||||
delete _conn;
|
||||
}
|
||||
|
|
@ -40,16 +42,21 @@ void mongo::Tool::printExtraHelp( ostream & out ){
|
|||
}
|
||||
|
||||
void mongo::Tool::printHelp(ostream &out) {
|
||||
_options->print(out);
|
||||
printExtraHelp(out);
|
||||
_options->print(out);
|
||||
}
|
||||
|
||||
int mongo::Tool::main( int argc , char ** argv ){
|
||||
boost::filesystem::path::default_name_check( boost::filesystem::no_check );
|
||||
|
||||
_name = argv[0];
|
||||
|
||||
try {
|
||||
po::options_description all_options("all options");
|
||||
all_options.add(*_options).add(*_hidden_options);
|
||||
|
||||
po::store( po::command_line_parser( argc , argv ).
|
||||
options( *_options ).
|
||||
options(all_options).
|
||||
positional( _positonalOptions ).run() , _params );
|
||||
|
||||
po::notify( _params );
|
||||
|
|
|
|||
|
|
@ -27,6 +27,9 @@ namespace mongo {
|
|||
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 );
|
||||
}
|
||||
|
|
@ -74,6 +77,7 @@ namespace mongo {
|
|||
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;
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ namespace po = boost::program_options;
|
|||
class Files : public Tool {
|
||||
public:
|
||||
Files() : Tool( "files" ){
|
||||
add_options()
|
||||
add_hidden_options()
|
||||
( "command" , po::value<string>() , "command (list|search|put|get)" )
|
||||
( "file" , po::value<string>() , "filename for get|put" )
|
||||
;
|
||||
|
|
@ -43,8 +43,14 @@ public:
|
|||
}
|
||||
|
||||
virtual void printExtraHelp( ostream & out ){
|
||||
out << "\t list - list all files. takes an optional filename. the file has to start with the filename" << endl;
|
||||
out << "\t search - search all files for something that contains the string" << endl;
|
||||
out << "usage: " << _name << " [options] command [filename]" << endl;
|
||||
out << "command:" << endl;
|
||||
out << " one of (list|search|put|get)" << endl;
|
||||
out << " list - list all files. takes an optional filename. " << endl;
|
||||
out << " listed files must start with the filename." << endl;
|
||||
out << " search - search all files for something that contains the string" << endl;
|
||||
out << " put - add a file" << endl;
|
||||
out << " get - get a file" << endl;
|
||||
}
|
||||
|
||||
void display( GridFS * grid , BSONObj obj ){
|
||||
|
|
|
|||
Loading…
Reference in New Issue