summaryrefslogtreecommitdiff
path: root/src/CommandLine.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2016-11-02 10:30:46 +0100
committerMax Kellermann <max@musicpd.org>2016-11-02 10:30:46 +0100
commitc8bb3c0b717bc0cd4fdfb40093963ce01a2d269b (patch)
tree049bcfde13eafb2e5dcf6582b52d3097f4dc5236 /src/CommandLine.cxx
parent9990e8473cd97b70a45ebaee626a0f5cf68eb585 (diff)
CommandLine: migrate from class Error to C++ exceptions
Diffstat (limited to 'src/CommandLine.cxx')
-rw-r--r--src/CommandLine.cxx35
1 files changed, 14 insertions, 21 deletions
diff --git a/src/CommandLine.cxx b/src/CommandLine.cxx
index 696a79474..1171828a1 100644
--- a/src/CommandLine.cxx
+++ b/src/CommandLine.cxx
@@ -35,8 +35,9 @@
#include "fs/Traits.hxx"
#include "fs/FileSystem.hxx"
#include "fs/StandardDirectory.hxx"
+#include "system/Error.hxx"
#include "util/Macros.hxx"
-#include "util/Error.hxx"
+#include "util/RuntimeError.hxx"
#include "util/Domain.hxx"
#include "util/OptionDef.hxx"
#include "util/OptionParser.hxx"
@@ -301,9 +302,8 @@ bool ConfigLoader::TryFile(const AllocatedPath &base_path,
return TryFile(full_path);
}
-bool
-parse_cmdline(int argc, char **argv, struct options *options,
- Error &error)
+void
+ParseCommandLine(int argc, char **argv, struct options *options)
{
bool use_config_file = true;
options->kill = false;
@@ -341,9 +341,8 @@ parse_cmdline(int argc, char **argv, struct options *options,
if (parser.CheckOption(opt_help, opt_help_alt))
help();
- error.Format(cmdline_domain, "invalid option: %s",
- parser.GetOption());
- return false;
+ throw FormatRuntimeError("invalid option: %s",
+ parser.GetOption());
}
/* initialize the logging library, so the configuration file
@@ -353,7 +352,7 @@ parse_cmdline(int argc, char **argv, struct options *options,
if (!use_config_file) {
LogDebug(cmdline_domain,
"Ignoring config, using daemon defaults");
- return true;
+ return;
}
// Second pass: find non-option parameters (i.e. config file)
@@ -365,8 +364,8 @@ parse_cmdline(int argc, char **argv, struct options *options,
config_file = argv[i];
continue;
}
- error.Set(cmdline_domain, "too many arguments");
- return false;
+
+ throw std::runtime_error("too many arguments");
}
if (config_file != nullptr) {
@@ -375,16 +374,14 @@ parse_cmdline(int argc, char **argv, struct options *options,
wchar_t buffer[MAX_PATH];
auto result = MultiByteToWideChar(CP_ACP, 0, config_file, -1,
buffer, ARRAY_SIZE(buffer));
- if (result <= 0) {
- error.SetLastError("MultiByteToWideChar() failed");
- return false;
- }
+ if (result <= 0)
+ throw MakeLastError("MultiByteToWideChar() failed");
ReadConfigFile(Path::FromFS(buffer));
#else
ReadConfigFile(Path::FromFS(config_file));
#endif
- return true;
+ return;
}
/* use default configuration file path */
@@ -403,10 +400,6 @@ parse_cmdline(int argc, char **argv, struct options *options,
loader.TryFile(GetHomeDir(), USER_CONFIG_FILE_LOCATION2) ||
loader.TryFile(Path::FromFS(SYSTEM_CONFIG_FILE_LOCATION));
#endif
- if (!found) {
- error.Set(cmdline_domain, "No configuration file found");
- return false;
- }
-
- return true;
+ if (!found)
+ throw std::runtime_error("No configuration file found");
}