Commit c81e652d authored by Lisa's avatar Lisa
Browse files

Operation order fixed in pakabei parser, removing some useless data too.

parent 867d4076
......@@ -158,7 +158,7 @@ void PakabeiParser::parse()
} else if (commandLine.isSet("h") || commandLine.isSet("help")) {
CommandLineUtils::printHelpMessage(acceptedOperations, acceptedOptions, m_data);
}
for (QHash<QString, APM::OperationType>::iterator it = typechars.begin(); it != typechars.end(); it++) {
if (commandLine.isSet(it.key())) {
if (m_type != APM::NoType) {
......@@ -170,18 +170,23 @@ void PakabeiParser::parse()
found << "Q";
}
/*
* We look only for the acceptable operations
* all the others, if present, will be spotted later
*/
/*
* We look only for the acceptable operations
* all the others, if present, will be spotted later
*/
foreach (AkabeiOperation op, acceptedOperations.values(m_type)) {
/*
* Saves up the commands for later inspection
*/
if (commandLine.isSet(op.commandShort()) || commandLine.isSet(op.commandLong())) {
m_operations.insert(op.name(), op);
m_operations.append( op.name() );
found << op.commandShort();
if (m_operations.size() > 1) {
m_operations.removeOne(APM::Remove);
m_operations.removeOne(APM::Install);
}
}
}
......@@ -191,14 +196,9 @@ void PakabeiParser::parse()
if (m_operations.isEmpty()) {
throw MissingOperationException();
}
/*
* Now we need some adjustments!
*/
if (m_operations.size() > 1 && (m_operations.contains(APM::Remove) || m_operations.contains(APM::Install))) {
m_operations.remove(APM::Remove);
m_operations.remove(APM::Install);
}
QSet<APM::OptionName> goodOptions = supportedOptions();
bool freeArgsRequired = areArgsRequired();
foreach (AkabeiOption opt, acceptedOptions) {
QString commandName = (opt.commandShort().isEmpty()) ? opt.commandLong() : opt.commandShort();
......@@ -207,14 +207,7 @@ void PakabeiParser::parse()
if ((!found.contains(commandName.toUtf8()) && commandLine.isSet(opt.commandShort())) || commandLine.isSet(opt.commandLong())) {
/* If at least one operation supports the option, it's fine */
bool supported = false;
foreach (AkabeiOperation op, m_operations.values()) {
if (op.isOptionSupported(opt.name())) {
supported = true;
break;
}
}
if (!supported) {
if (!goodOptions.contains( opt.name() )) {
throw OptionOutOfContextException(commandName);
}
......@@ -245,32 +238,51 @@ void PakabeiParser::parse()
* -Sy with args first updates and then installs the packages
*/
if (!m_freeArgs.isEmpty() && m_operations.contains(APM::UpdateDatabases)) {
m_operations.insert(APM::Install, specialOperations[APM::Install]);
m_operations.append(APM::Install);
}
/*if (!m_freeArgs.isEmpty() && !freeArgsRequired()) {
throw ArgumentsOutOfContextException();
}*///NOTE: We don't throw this anymore, as we could have arguments, but not needed... e.g. akabei files can have -p /path/to/package OR an argument
if (m_freeArgs.isEmpty() && freeArgsRequired()) {
if (m_freeArgs.isEmpty() && freeArgsRequired) {
throw ExpectedArgumentsException();
}
commandLine.emptyCheck();
}
/*
* If at least one operation in the chain requires free args, they're required
* Arguments are required if at least one operation requires them.
*/
bool PakabeiParser::freeArgsRequired()
bool PakabeiParser::areArgsRequired()
{
foreach (const AkabeiOperation& op, m_operations.values()) {
if (op.hasFreeArgs()) {
return true;
bool req = false;
foreach (const AkabeiOperation& operation, acceptedOperations.values()) {
if (m_operations.contains( operation.name() )) {
req = req || operation.hasFreeArgs();
}
}
return req;
}
return false;
/*
* Returns a set of all the supported options. An option is supported if at least one
* operation accepts it.
*/
QSet< APM::OptionName > PakabeiParser::supportedOptions()
{
QSet<APM::OptionName> supported;
foreach (const AkabeiOperation& operation, acceptedOperations.values()) {
if (m_operations.contains( operation.name() )) {
supported += QSet<APM::OptionName>::fromList( operation.options() );
}
}
return supported;
}
APM::OperationType PakabeiParser::type()
......@@ -280,7 +292,7 @@ APM::OperationType PakabeiParser::type()
QList<APM::OperationName> PakabeiParser::operations()
{
return m_operations.keys();
return m_operations;
}
QStringList PakabeiParser::args()
......
......@@ -65,7 +65,7 @@ class PakabeiParser : public CommandLineParser
{
private:
APM::OperationType m_type;
QMap<APM::OperationName, AkabeiOperation> m_operations;
QList<APM::OperationName> m_operations;
QHash<APM::OptionName, AkabeiOption> m_options;
QStringList m_freeArgs;
......@@ -76,11 +76,9 @@ private:
QMultiHash<APM::OperationType, AkabeiOperation> acceptedOperations;
QList<AkabeiOption> acceptedOptions;
QHash<QString, APM::OperationType> typechars;
/* I'm sorry for this, but it speeds up one particular stage */
QHash<APM::OperationName, AkabeiOperation> specialOperations;
bool freeArgsRequired();
QSet<APM::OptionName> supportedOptions();
bool areArgsRequired();
public:
PakabeiParser(int argc, char **argv, KAboutData &);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment