mirror of https://github.com/aria2/aria2
Don't exit on error in option_processing
Still it exits when -v or -h is given. They are now guarded by standalone variable and only do so when it is true.libaria2
parent
e5cccd335c
commit
aee621b3d4
|
@ -175,17 +175,25 @@ void showFiles
|
||||||
} // namespace
|
} // namespace
|
||||||
#endif // ENABLE_BITTORRENT || ENABLE_METALINK
|
#endif // ENABLE_BITTORRENT || ENABLE_METALINK
|
||||||
|
|
||||||
extern void option_processing(Option& option, bool standalone,
|
extern error_code::Value option_processing(Option& option, bool standalone,
|
||||||
std::vector<std::string>& uris,
|
std::vector<std::string>& uris,
|
||||||
int argc, char** argv, const KeyVals& options);
|
int argc, char** argv,
|
||||||
|
const KeyVals& options);
|
||||||
|
|
||||||
Context::Context(bool standalone,
|
Context::Context(bool standalone,
|
||||||
int argc, char** argv, const KeyVals& options)
|
int argc, char** argv, const KeyVals& options)
|
||||||
{
|
{
|
||||||
std::vector<std::string> args;
|
std::vector<std::string> args;
|
||||||
SharedHandle<Option> op(new Option());
|
SharedHandle<Option> op(new Option());
|
||||||
option_processing(*op.get(), standalone, args, argc, argv, options);
|
error_code::Value rv;
|
||||||
|
rv = option_processing(*op.get(), standalone, args, argc, argv, options);
|
||||||
|
if(rv != error_code::FINISHED) {
|
||||||
|
if(standalone) {
|
||||||
|
exit(rv);
|
||||||
|
} else {
|
||||||
|
throw DL_ABORT_EX("Option processing failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
SimpleRandomizer::init();
|
SimpleRandomizer::init();
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
bittorrent::generateStaticPeerId(op->get(PREF_PEER_ID_PREFIX));
|
bittorrent::generateStaticPeerId(op->get(PREF_PEER_ID_PREFIX));
|
||||||
|
|
|
@ -85,7 +85,12 @@ int libraryDeinit()
|
||||||
Session* sessionNew(const KeyVals& options)
|
Session* sessionNew(const KeyVals& options)
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
Session* session = new Session(options);
|
Session* session;
|
||||||
|
try {
|
||||||
|
session = new Session(options);
|
||||||
|
} catch(RecoverableException& e) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if(session->context->reqinfo) {
|
if(session->context->reqinfo) {
|
||||||
rv = session->context->reqinfo->prepare();
|
rv = session->context->reqinfo->prepare();
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
|
|
|
@ -190,9 +190,10 @@ void optionNativeToUtf8(Option& op)
|
||||||
} // namespace
|
} // namespace
|
||||||
#endif // __MINGW32__
|
#endif // __MINGW32__
|
||||||
|
|
||||||
void option_processing(Option& op, bool standalone,
|
error_code::Value option_processing(Option& op, bool standalone,
|
||||||
std::vector<std::string>& uris,
|
std::vector<std::string>& uris,
|
||||||
int argc, char** argv, const KeyVals& options)
|
int argc, char** argv,
|
||||||
|
const KeyVals& options)
|
||||||
{
|
{
|
||||||
const SharedHandle<OptionParser>& oparser = OptionParser::getInstance();
|
const SharedHandle<OptionParser>& oparser = OptionParser::getInstance();
|
||||||
try {
|
try {
|
||||||
|
@ -206,27 +207,28 @@ void option_processing(Option& op, bool standalone,
|
||||||
oparser->parse(op, cmdstream);
|
oparser->parse(op, cmdstream);
|
||||||
noConf = op.getAsBool(PREF_NO_CONF);
|
noConf = op.getAsBool(PREF_NO_CONF);
|
||||||
ucfname = op.get(PREF_CONF_PATH);
|
ucfname = op.get(PREF_CONF_PATH);
|
||||||
|
if(standalone) {
|
||||||
if(op.defined(PREF_VERSION)) {
|
if(op.defined(PREF_VERSION)) {
|
||||||
showVersion();
|
showVersion();
|
||||||
exit(error_code::FINISHED);
|
exit(error_code::FINISHED);
|
||||||
}
|
}
|
||||||
if(op.defined(PREF_HELP)) {
|
if(op.defined(PREF_HELP)) {
|
||||||
std::string keyword;
|
std::string keyword;
|
||||||
if(op.get(PREF_HELP).empty()) {
|
if(op.get(PREF_HELP).empty()) {
|
||||||
keyword = strHelpTag(TAG_BASIC);
|
keyword = strHelpTag(TAG_BASIC);
|
||||||
} else {
|
} else {
|
||||||
keyword = op.get(PREF_HELP);
|
keyword = op.get(PREF_HELP);
|
||||||
if(util::startsWith(keyword, "--")) {
|
if(util::startsWith(keyword, "--")) {
|
||||||
keyword.erase(keyword.begin(), keyword.begin()+2);
|
keyword.erase(keyword.begin(), keyword.begin()+2);
|
||||||
}
|
}
|
||||||
std::string::size_type eqpos = keyword.find("=");
|
std::string::size_type eqpos = keyword.find("=");
|
||||||
if(eqpos != std::string::npos) {
|
if(eqpos != std::string::npos) {
|
||||||
keyword.erase(keyword.begin()+eqpos, keyword.end());
|
keyword.erase(keyword.begin()+eqpos, keyword.end());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
showUsage(keyword, oparser, global::cout());
|
||||||
|
exit(error_code::FINISHED);
|
||||||
}
|
}
|
||||||
showUsage(keyword, oparser, global::cout());
|
|
||||||
exit(error_code::FINISHED);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SharedHandle<Option> confOption(new Option());
|
SharedHandle<Option> confOption(new Option());
|
||||||
|
@ -254,18 +256,18 @@ void option_processing(Option& op, bool standalone,
|
||||||
global::cerr()->printf(_("Usage:"));
|
global::cerr()->printf(_("Usage:"));
|
||||||
global::cerr()->printf("\n%s\n", h->getDescription());
|
global::cerr()->printf("\n%s\n", h->getDescription());
|
||||||
}
|
}
|
||||||
exit(e.getErrorCode());
|
return e.getErrorCode();
|
||||||
} catch(Exception& e) {
|
} catch(Exception& e) {
|
||||||
global::cerr()->printf(_("Parse error in %s"), cfname.c_str());
|
global::cerr()->printf(_("Parse error in %s"), cfname.c_str());
|
||||||
global::cerr()->printf("\n%s", e.stackTrace().c_str());
|
global::cerr()->printf("\n%s", e.stackTrace().c_str());
|
||||||
exit(e.getErrorCode());
|
return e.getErrorCode();
|
||||||
}
|
}
|
||||||
} else if(!ucfname.empty()) {
|
} else if(!ucfname.empty()) {
|
||||||
global::cerr()->printf(_("Configuration file %s is not found."),
|
global::cerr()->printf(_("Configuration file %s is not found."),
|
||||||
cfname.c_str());
|
cfname.c_str());
|
||||||
global::cerr()->printf("\n");
|
global::cerr()->printf("\n");
|
||||||
showUsage(strHelpTag(TAG_HELP), oparser, global::cerr());
|
showUsage(strHelpTag(TAG_HELP), oparser, global::cerr());
|
||||||
exit(error_code::UNKNOWN_ERROR);
|
return error_code::UNKNOWN_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Override configuration with environment variables.
|
// Override configuration with environment variables.
|
||||||
|
@ -298,15 +300,15 @@ void option_processing(Option& op, bool standalone,
|
||||||
global::cerr()->printf("\n");
|
global::cerr()->printf("\n");
|
||||||
write(global::cerr(), *h);
|
write(global::cerr(), *h);
|
||||||
}
|
}
|
||||||
exit(e.getErrorCode());
|
return e.getErrorCode();
|
||||||
} catch(UnknownOptionException& e) {
|
} catch(UnknownOptionException& e) {
|
||||||
showUsage("", oparser, global::cerr());
|
showUsage("", oparser, global::cerr());
|
||||||
showCandidates(e.getUnknownOption(), oparser);
|
showCandidates(e.getUnknownOption(), oparser);
|
||||||
exit(e.getErrorCode());
|
return e.getErrorCode();
|
||||||
} catch(Exception& e) {
|
} catch(Exception& e) {
|
||||||
global::cerr()->printf("%s", e.stackTrace().c_str());
|
global::cerr()->printf("%s", e.stackTrace().c_str());
|
||||||
showUsage("", oparser, global::cerr());
|
showUsage("", oparser, global::cerr());
|
||||||
exit(e.getErrorCode());
|
return e.getErrorCode();
|
||||||
}
|
}
|
||||||
if(standalone &&
|
if(standalone &&
|
||||||
!op.getAsBool(PREF_ENABLE_RPC) &&
|
!op.getAsBool(PREF_ENABLE_RPC) &&
|
||||||
|
@ -321,15 +323,16 @@ void option_processing(Option& op, bool standalone,
|
||||||
global::cerr()->printf(MSG_URI_REQUIRED);
|
global::cerr()->printf(MSG_URI_REQUIRED);
|
||||||
global::cerr()->printf("\n");
|
global::cerr()->printf("\n");
|
||||||
showUsage("", oparser, global::cerr());
|
showUsage("", oparser, global::cerr());
|
||||||
exit(error_code::UNKNOWN_ERROR);
|
return error_code::UNKNOWN_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(op.getAsBool(PREF_DAEMON)) {
|
if(op.getAsBool(PREF_DAEMON)) {
|
||||||
if(daemon(0, 0) < 0) {
|
if(daemon(0, 0) < 0) {
|
||||||
perror(MSG_DAEMON_FAILED);
|
perror(MSG_DAEMON_FAILED);
|
||||||
exit(error_code::UNKNOWN_ERROR);
|
return error_code::UNKNOWN_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return error_code::FINISHED;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
Loading…
Reference in New Issue