Commit e436e814 authored by Lisa's avatar Lisa

More const references; nosave option now correctly managed; bug fixed

parent 8431c309
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <kaboutdata.h> #include <kaboutdata.h>
#include <klocalizedstring.h> #include <klocalizedstring.h>
/* /*
* Build our database of accepted operations and options with the right properties and associations * Build our database of accepted operations and options with the right properties and associations
*/ */
...@@ -39,7 +40,7 @@ CmdLine::CmdLine() ...@@ -39,7 +40,7 @@ CmdLine::CmdLine()
AkabeiOption ignore(APM::Ignore, "", "ignore", "Ignores a certain package. Can be used more than once.", true); AkabeiOption ignore(APM::Ignore, "", "ignore", "Ignores a certain package. Can be used more than once.", true);
AkabeiOption ignoregroup(APM::IgnoreGroup, "", "ignoregroup", "Ignores upgrade of a group", true); AkabeiOption ignoregroup(APM::IgnoreGroup, "", "ignoregroup", "Ignores upgrade of a group", true);
AkabeiOption databaseonly(APM::DatabaseOnly, "k", "dbonly", "Only remove database entries", false); AkabeiOption databaseonly(APM::DatabaseOnly, "k", "dbonly", "Only remove database entries", false);
AkabeiOption removeconfig(APM::RemoveConfig, "n", "nsave", "Also remove configuration files", false); AkabeiOption removeconfig(APM::RemoveConfig, "n", "nosave", "Also remove configuration files", false);
AkabeiOption recursive(APM::Recursive, "s", "recursive", "Remove dependencies as well. (-ss includes explicitely installed dependencies)", false); AkabeiOption recursive(APM::Recursive, "s", "recursive", "Remove dependencies as well. (-ss includes explicitely installed dependencies)", false);
AkabeiOption rootdir(APM::RootDir, "", "root", "Set a different root dir", true); AkabeiOption rootdir(APM::RootDir, "", "root", "Set a different root dir", true);
AkabeiOption cachedir(APM::CacheDir, "", "cachedir", "Set a different cache dir", true); AkabeiOption cachedir(APM::CacheDir, "", "cachedir", "Set a different cache dir", true);
...@@ -154,23 +155,27 @@ CmdLine::CmdLine() ...@@ -154,23 +155,27 @@ CmdLine::CmdLine()
AkabeiOperation version(APM::NoType, APM::Version, "v", "version", "Shows Akabei version", false); AkabeiOperation version(APM::NoType, APM::Version, "v", "version", "Shows Akabei version", false);
AkabeiOperationList tmp; QList<AkabeiOperation *> tmp;
tmp << removeallcache << help << version << install << remove << database << changelog << installedasdeps << installedexp; tmp << &removeallcache << &help << &version << &install << &remove << &database << &changelog << &installedasdeps << &installedexp;
tmp << checkfiles << showowner << notrequired << upgradeable << cascade; tmp << &checkfiles << &showowner << &notrequired << &upgradeable << &cascade;
tmp << removeold << groups << info << listrepo << groupsl << searchl << infol; tmp << &removeold << &groups << &info << &listrepo << &groupsl << &searchl << &infol;
tmp << search << updatedb << updatesys << updatedbandsys << upgrade; tmp << &search << &updatedb << &updatesys << &updatedbandsys << &upgrade;
/* These are the only operation we need to access directly later, so better speed up searches a bit */
specialOperations << removeallcache << help << version;
foreach (AkabeiOperation op, tmp) { /*
* It has to be pointers otherwise the changes in this foreach
* aren't reflected in specialOperations below
*/
foreach (AkabeiOperation *op, tmp) {
/* These options are associated to every operation */ /* These options are associated to every operation */
op.addOption(rootdir); op->addOption(rootdir);
op.addOption(cachedir); op->addOption(cachedir);
op.addOption(dbpath); op->addOption(dbpath);
acceptedOperations.insertMulti(op.type, op); acceptedOperations.insertMulti(op->type, *op);
} }
/* These are the only operation we need to access directly later, so better speed up searches a bit */
specialOperations << removeallcache << help << version;
} }
AkabeiOption::AkabeiOption(APM::OptionName n, const char *cs, const char *cl, const char *desc, bool hasArg) AkabeiOption::AkabeiOption(APM::OptionName n, const char *cs, const char *cl, const char *desc, bool hasArg)
...@@ -286,7 +291,7 @@ void CmdLine::parse(int argc, char** argv) ...@@ -286,7 +291,7 @@ void CmdLine::parse(int argc, char** argv)
/* /*
* Adds all the operations * Adds all the operations
*/ */
foreach (AkabeiOperation op, acceptedOperations.values()) { foreach (const AkabeiOperation& op, acceptedOperations.values()) {
if (!op.commandShort.isEmpty()) { if (!op.commandShort.isEmpty()) {
if (!op.commandLong.isEmpty()) { if (!op.commandLong.isEmpty()) {
koptions.add(op.commandLong); koptions.add(op.commandLong);
...@@ -299,7 +304,7 @@ void CmdLine::parse(int argc, char** argv) ...@@ -299,7 +304,7 @@ void CmdLine::parse(int argc, char** argv)
* Adds all the option with <argument> if they require one * Adds all the option with <argument> if they require one
* TODO: make <argument> more explicative of its nature (package, group, filename, ...) * TODO: make <argument> more explicative of its nature (package, group, filename, ...)
*/ */
foreach (AkabeiOption opt, acceptedOptions) { foreach (const AkabeiOption& opt, acceptedOptions) {
QByteArray newcomlong = opt.commandLong; QByteArray newcomlong = opt.commandLong;
if (opt.hasArg) { if (opt.hasArg) {
newcomlong += " <argument>"; newcomlong += " <argument>";
...@@ -392,10 +397,16 @@ void CmdLine::parse(int argc, char** argv) ...@@ -392,10 +397,16 @@ void CmdLine::parse(int argc, char** argv)
foreach (AkabeiOption opt, acceptedOptions) { foreach (AkabeiOption opt, acceptedOptions) {
QByteArray command = (opt.commandShort.isEmpty()) ? opt.commandLong : opt.commandShort; QByteArray command = (opt.commandShort.isEmpty()) ? opt.commandLong : opt.commandShort;
/* bool condition = !found.contains(command); /* if found contains the command, we already decided it's an operation */
* If "found" contains the command, we it was an operation, so go on
*/ /* This is a special case for cause of the "nosave" option */
if (!found.contains(command) && args->isSet(command)) { if (opt.name == APM::RemoveConfig) {
condition &= !args->isSet("save");
} else {
condition &= args->isSet(command); /* normal check */
}
if (condition) {
if (!m_operation.isOptionSupported(opt.name)) { if (!m_operation.isOptionSupported(opt.name)) {
throw CmdLineException("invalid option for this operation"); throw CmdLineException("invalid option for this operation");
} }
...@@ -509,7 +520,7 @@ void CmdLine::secondParse(QStringList args, QList<QByteArray>& foundCmds) ...@@ -509,7 +520,7 @@ void CmdLine::secondParse(QStringList args, QList<QByteArray>& foundCmds)
* If the command line contains something else other than what we have already parsed * If the command line contains something else other than what we have already parsed
* there's something wrong around * there's something wrong around
*/ */
foreach (QByteArray com, cmdline) { foreach (const QByteArray& com, cmdline) {
if (!foundCmds.contains(com)) { if (!foundCmds.contains(com)) {
throw CmdLineException("Out of context operation"); throw CmdLineException("Out of context operation");
} }
...@@ -526,7 +537,7 @@ void CmdLine::secondParse(QStringList args, QList<QByteArray>& foundCmds) ...@@ -526,7 +537,7 @@ void CmdLine::secondParse(QStringList args, QList<QByteArray>& foundCmds)
/* /*
* Counts the occurrence of all the options we previously found * Counts the occurrence of all the options we previously found
*/ */
foreach (AkabeiOption opt, m_options.values()) { foreach (const AkabeiOption& opt, m_options.values()) {
/* The only options allowed to be repeated several times */ /* The only options allowed to be repeated several times */
if (opt.name == APM::Ignore || opt.name == APM::IgnoreGroup) { if (opt.name == APM::Ignore || opt.name == APM::IgnoreGroup) {
......
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