mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
SERVER-1687 .mongorc.js file is read from home directory on shell startup
This commit is contained in:
parent
21217ca8b7
commit
d3d1f32427
@ -480,6 +480,7 @@ int _main(int argc, char* argv[]) {
|
||||
|
||||
bool runShell = false;
|
||||
bool nodb = false;
|
||||
bool norc = false;
|
||||
|
||||
string script;
|
||||
|
||||
@ -491,6 +492,7 @@ int _main(int argc, char* argv[]) {
|
||||
shell_options.add_options()
|
||||
("shell", "run the shell after executing files")
|
||||
("nodb", "don't connect to mongod on startup - no 'db address' arg expected")
|
||||
("norc", "will not run the \".mongorc.js\" file on start up")
|
||||
("quiet", "be less chatty" )
|
||||
("port", po::value<string>(&port), "port to connect to")
|
||||
("host", po::value<string>(&dbhost), "server to connect to")
|
||||
@ -553,6 +555,9 @@ int _main(int argc, char* argv[]) {
|
||||
if (params.count("nodb")) {
|
||||
nodb = true;
|
||||
}
|
||||
if (params.count("norc")) {
|
||||
norc = true;
|
||||
}
|
||||
if (params.count("help")) {
|
||||
show_help_text(argv[0], shell_options);
|
||||
return mongo::EXIT_CLEAN;
|
||||
@ -667,6 +672,23 @@ int _main(int argc, char* argv[]) {
|
||||
|
||||
mongo::shellUtils::MongoProgramScope s;
|
||||
|
||||
if (!norc) {
|
||||
string rcLocation;
|
||||
#ifndef _WIN32
|
||||
if ( getenv("HOME") != NULL )
|
||||
rcLocation = str::stream() << getenv("HOME") << "/.mongorc.js" ;
|
||||
#else
|
||||
if ( getenv("HOMEDRIVE") != NULL && getenv("HOMEPATH") != NULL )
|
||||
rcLocation = str::stream() << getenv("HOMEDRIVE") << getenv("HOMEPATH") << "\\.mongorc.js";
|
||||
#endif
|
||||
if ( !rcLocation.empty() && fileExists(rcLocation) ) {
|
||||
if ( ! scope->execFile( rcLocation , false , true , false , 0 ) ) {
|
||||
cout << "The \".mongorc.js\" file located in your home folder could not be executed" << endl;
|
||||
return -5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
shellHistoryInit();
|
||||
|
||||
string prompt;
|
||||
|
Loading…
Reference in New Issue
Block a user