2016-04-18 20:33:43 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-04-18 20:33:43 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-04-18 20:33:43 +00:00
|
|
|
*/
|
|
|
|
#include "codegen/numbers/options.h"
|
|
|
|
|
|
|
|
#include <ostream>
|
|
|
|
#include <QtCore/QCoreApplication>
|
|
|
|
#include "codegen/common/logging.h"
|
|
|
|
|
|
|
|
namespace codegen {
|
|
|
|
namespace numbers {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr int kErrorOutputPathExpected = 902;
|
|
|
|
constexpr int kErrorInputPathExpected = 903;
|
|
|
|
constexpr int kErrorSingleInputPathExpected = 904;
|
2017-04-12 19:17:55 +00:00
|
|
|
constexpr int kErrorWorkingPathExpected = 905;
|
2016-04-18 20:33:43 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
using common::logError;
|
|
|
|
|
|
|
|
Options parseOptions() {
|
|
|
|
Options result;
|
2017-02-15 08:50:11 +00:00
|
|
|
auto args = QCoreApplication::instance()->arguments();
|
|
|
|
for (auto i = 1, count = args.size(); i < count; ++i) { // skip first
|
|
|
|
auto &arg = args.at(i);
|
2016-04-18 20:33:43 +00:00
|
|
|
|
|
|
|
// Output path
|
|
|
|
if (arg == "-o") {
|
|
|
|
if (++i == count) {
|
|
|
|
logError(kErrorOutputPathExpected, "Command Line") << "output path expected after -o";
|
|
|
|
return Options();
|
|
|
|
} else {
|
|
|
|
result.outputPath = args.at(i);
|
|
|
|
}
|
|
|
|
} else if (arg.startsWith("-o")) {
|
|
|
|
result.outputPath = arg.mid(2);
|
|
|
|
|
2017-04-12 19:17:55 +00:00
|
|
|
// Working path
|
|
|
|
} else if (arg == "-w") {
|
|
|
|
if (++i == count) {
|
|
|
|
logError(kErrorWorkingPathExpected, "Command Line") << "working path expected after -w";
|
|
|
|
return Options();
|
|
|
|
} else {
|
|
|
|
common::logSetWorkingPath(args.at(i));
|
|
|
|
}
|
|
|
|
} else if (arg.startsWith("-w")) {
|
|
|
|
common::logSetWorkingPath(arg.mid(2));
|
|
|
|
|
2016-04-18 20:33:43 +00:00
|
|
|
// Input path
|
|
|
|
} else {
|
|
|
|
if (result.inputPath.isEmpty()) {
|
|
|
|
result.inputPath = arg;
|
|
|
|
} else {
|
|
|
|
logError(kErrorSingleInputPathExpected, "Command Line") << "only one input path expected";
|
|
|
|
return Options();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (result.inputPath.isEmpty()) {
|
|
|
|
logError(kErrorInputPathExpected, "Command Line") << "input path expected";
|
|
|
|
return Options();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace numbers
|
|
|
|
} // namespace codegen
|