Beispiel #1
0
int Tool::run(const std::deque<std::string> &args) {
	_arguments = args;

	// Pop the first argument (name of ourselves)
	_arguments.pop_front();

	// Check for help
	if (_arguments.empty() || _arguments.front() == "-h" || _arguments.front() == "--help") {
		print(getHelp());
		return 2;
	}

	// Check for version
	if (_arguments.front() == "--version") {
		print(getVersion());
		return 2;
	}

	// Read standard arguments
	parseAudioArguments();
	parseOutputArguments();
	// Read tool specific arguments
	parseExtraArguments();

	if (!_arguments.empty() && _arguments.front()[0] == '-') {
		std::string s = "Possibly ignored option " + _arguments.front() + ".\n";
		print(s);
	}

	// Make sure we have enough input files.
	if (_arguments.size() < _inputPaths.size()) {
		print("Too few input files!\n");
		return -2;
	}

	// Read input files from CLI
	for (ToolInputs::iterator iter = _inputPaths.begin(); iter != _inputPaths.end(); ++iter) {
		std::string in = _arguments.front();
		_arguments.pop_front();
		if (!iter->file) {
			// Append '/' to input if it's not already done
			// TODO: We need a way to detect a proper directory here!
			size_t s = in.size();
			if (in[s-1] == '/' || in[s-1] == '\\') {
				in[s] = '/';
				in[s+1] = '\0';
			}
		}

		iter->path = in;
	}

	// We should have parsed all arguments by now
	if (_inputPaths.size() < _arguments.size()) {
		std::ostringstream os;
		os << "Too many inputs files ( ";
		while (!_arguments.empty()) {
			os << "'" << _arguments.front() << "' ";
			_arguments.pop_front();
		}
		os << ")\n";
		print(os.str());
		return -2;
	}

	if (_inputPaths.empty()) {
		// Display help text if we got no input
		print(_helptext);
		return 2;
	}

	// Run the tool, with error handling
	try {
		run();
	} catch(ToolException &err) {
		const char *what = err.what();
		print("Fatal Error : %s\n", what);
		return err._retcode;
	}
	return 0;
}
Beispiel #2
0
int Tool::run(const std::deque<std::string> &args) {
	_arguments = args;

	// Pop the first argument (name of ourselves)
	_arguments.pop_front();

	// Check for help
	if (_arguments.empty() || _arguments.front() == "-h" || _arguments.front() == "--help") {
		print(getHelp());
		return 2;
	}

	// Check for version
	if (_arguments.front() == "--version") {
		print(getVersion());
		return 2;
	}

	// Read standard arguments
	parseAudioArguments();
	parseOutputArguments();
	// Read tool specific arguments
	parseExtraArguments();

	if (!_arguments.empty() && _arguments.front()[0] == '-') {
		std::string s = "Possibly ignored option " + _arguments.front() + ".";
		print(s);
	}

	// Make sure we have enough input files.
	if (_arguments.size() < _inputPaths.size()) {
		print("Too few input files!");
		return -2;
	}

	// Read input files from CLI and match them to expected input.
	// First make sure the all the input paths are unset 
	clearInputPaths();
	// Then match the remaining arguments with the input paths.
	int nbExpectedInputs = _inputPaths.size();
	for (int i = 0 ; i < nbExpectedInputs ; ++i) {
		std::string in = _arguments.front();
		_arguments.pop_front();
		if (!addInputPath(in)) {
			print("Unexpected input file '%s'!", in.c_str());
			return -2;
		}
	}

	// We should have parsed all arguments by now
	if (!_arguments.empty()) {
		std::ostringstream os;
		os << "Too many inputs files ( ";
		while (!_arguments.empty()) {
			os << "'" << _arguments.front() << "' ";
			_arguments.pop_front();
		}
		os << ")";
		print(os.str());
		return -2;
	}

	if (_inputPaths.empty()) {
		// Display help text if we got no input
		print(_helptext);
		return 2;
	}

	// Run the tool, with error handling
	try {
		run();
	} catch(ToolException &err) {
		const char *what = err.what();
		print("Fatal Error : %s", what);
		return err._retcode;
	}
	return 0;
}