Commit 27076c1b authored by Lisa's avatar Lisa

Long commands now supported

parent f83718cd
......@@ -41,7 +41,7 @@ CmdLine::CmdLine()
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 databaseonly(APM::DatabaseOnly, "k", "dbonly", "Only remove database entries", false);
AkabeiOption removeconfig(APM::RemoveConfig, "n", "save", "Also remove configuration files", false);
AkabeiOption removeconfig(APM::RemoveConfig, "n", "nsave", "Also remove configuration files", 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 cachedir(APM::CacheDir, "", "cachedir", "Set a different cache dir", true);
......@@ -51,7 +51,7 @@ CmdLine::CmdLine()
acceptedOptions << force << downloadonly << onlyneeded << ignore << ignoregroup << databaseonly << removeconfig << recursive;
acceptedOptions << rootdir << cachedir << dbpath;
AkabeiOperation database(APM::DatabaseOperationType, APM::DatabaseOperation, "D", "", "", false);
AkabeiOperation database(APM::DatabaseOperationType, APM::DatabaseOperation, "D", "", "Database operation", false);
AkabeiOperation changelog(APM::QueryOperationType, APM::ShowChangelog, "c", "changelog", "Shows changelog of the package", true);
changelog.addOption(querypkgfile);
......@@ -156,13 +156,12 @@ CmdLine::CmdLine()
AkabeiOperation version(APM::NoType, APM::Version, "v", "version", "Shows Akabei version", false);
AkabeiOperationList tmp2;
tmp2 << removeallcache << install << remove << database << changelog << installedasdeps << installedexp;
tmp2 << checkfiles << showowner << notrequired << upgradeable << cascade;
tmp2 << removeold << groups << info << listrepo << groupsl << searchl << infol;
tmp2 << search << updatedb << updatesys << updatedbandsys << upgrade << help << version;
acceptedOperationsList << removeallcache << install << remove << database << changelog << installedasdeps << installedexp;
acceptedOperationsList << checkfiles << showowner << notrequired << upgradeable << cascade;
acceptedOperationsList << removeold << groups << info << listrepo << groupsl << searchl << infol;
acceptedOperationsList << search << updatedb << updatesys << updatedbandsys << upgrade << help << version;
foreach (AkabeiOperation op, tmp2) {
foreach (AkabeiOperation op, acceptedOperationsList) {
/* These options are associated to every operation */
op.addOption(rootdir);
op.addOption(cachedir);
......@@ -231,16 +230,11 @@ AkabeiOperation::AkabeiOperation()
*/
void AkabeiOperation::set(AkabeiOperation& other)
{
if ((this->type == APM::SyncOperationType && other.name == APM::Install) || (this->type == APM::RemoveOperationType && other.name == APM::Remove) || (this->name == APM::RemoveAllCache && other.commandShort == "c")) {
if ((this->type == APM::SyncOperationType && other.name == APM::Install) || (this->type == APM::RemoveOperationType && other.name == APM::Remove)) {
return;
}
/* This is because sometimes the same operation is checked twice (also due to the hash) */
if (this->name == other.name) {
return;
}
if (this->name == APM::None || this->name == APM::Remove || this->name == APM::Install) {
if (this->name == APM::None || this->name == APM::Remove || this->name == APM::Install || (this->commandShort == "c" && other.name == APM::RemoveAllCache)) {
this->name = other.name;
this->type = other.type;
this->options = other.options;
......@@ -252,7 +246,7 @@ void AkabeiOperation::set(AkabeiOperation& other)
this->type = APM::SyncOperationType;
this->hasFreeArgs = false;
} else {
throw CmdLineException("Multiple operations present.");
throw CmdLineException("multiple operations present.");
}
}
......@@ -294,26 +288,18 @@ void CmdLine::parse(int argc, char** argv)
KCmdLineOptions koptions;
/*
* Adds all the types
* Adds the only type which is not an operation
*/
koptions.add("D", ki18n("Database"));
koptions.add("S", ki18n("Install"));
koptions.add("U", ki18n("Upgrade"));
koptions.add("R", ki18n("Remove"));
koptions.add("Q", ki18n("Query"));
koptions.add("Q", ki18n("Query operation"));
/*
* Adds all the operations
*/
foreach (AkabeiOperation op, acceptedOperations.values()) {
if (!op.commandLong.isEmpty()) {
if (!op.commandShort.isEmpty()) {
koptions.add(op.commandShort);
foreach (AkabeiOperation op, acceptedOperationsList) {
if (!op.commandShort.isEmpty()) {
if (!op.commandLong.isEmpty()) {
koptions.add(op.commandLong);
}
koptions.add(op.commandLong, op.description);
}
else {
koptions.add(op.commandShort, op.description);
}
}
......@@ -370,7 +356,7 @@ void CmdLine::parse(int argc, char** argv)
* so we have to consider all the possibilities for whatever we find on the command line
*/
foreach (QByteArray command, acceptedOperations.uniqueKeys()) {
if (command.isEmpty()) {
if (command.isEmpty() || command.size() > 2) {
continue;
}
......@@ -379,13 +365,12 @@ void CmdLine::parse(int argc, char** argv)
* If found, set it as operation.
*/
if (args->isSet(command)) {
qDebug() << "found" << command;
bool found = false;
foreach (AkabeiOperation op, acceptedOperations.values(command)) {
if (op.type == type) {
foreach (AkabeiOperation candidate, acceptedOperations.values(command)) {
if (candidate.type == type) {
found = true;
m_operation.set(op);
m_operation.set(candidate);
/* Save it so it isn't searched again as an option */
checkops.append(command);
......@@ -457,9 +442,8 @@ void CmdLine::parse(int argc, char** argv)
* If that strange command wasn't an option, then it was something wrong
*/
if (!checkopts.isEmpty()) {
qDebug() << "this";
QString command = "the operation \"" + checkops.takeFirst() + "\" is out of context.";
throw CmdLineException(command.toUtf8().data());
QString message = "the operation \"" + checkopts.takeFirst() + "\" is out of context.";
throw CmdLineException(message.toUtf8().data());
}
for (int i = 0; i < args->count(); i++) {
......@@ -476,7 +460,7 @@ void CmdLine::parse(int argc, char** argv)
args->clear(); /* frees up memory */
secondParse(argc, argv);
secondParse(KCmdLineArgs::allArguments());
parsed = true;
}
......@@ -484,13 +468,11 @@ void CmdLine::parse(int argc, char** argv)
* This function handles all the parsing which can't be handled using KCmdLineArgs
* In particular, checks if the operation is repeated more than one, which isn't accepted
*/
void CmdLine::secondParse(int argc, char** argv)
void CmdLine::secondParse(QStringList args)
{
QStringList cmdline;
for (int i = 1; i < argc; i++) {
QString part = QString::fromAscii(argv[i]);
foreach (QString part, args) {
if (part.size() < 2) {
continue;
}
......@@ -507,6 +489,10 @@ void CmdLine::secondParse(int argc, char** argv)
if (part.count("cc") > 1) {
throw CmdLineException("can't accept linked operations.");
} else {
/* This must be put here because KCmdLineArgs doesn't always recognize this option */
AkabeiOperation special = acceptedOperations.take("cc");
m_operation.set(special);
part.remove("cc");
}
}
......
......@@ -122,12 +122,13 @@ private:
/* Database */
QMultiHash<QByteArray, AkabeiOperation> acceptedOperations;
AkabeiOperationList acceptedOperationsList;
AkabeiOptionList acceptedOptions;
QHash<QByteArray, APM::OperationType> typechars;
bool parsed;
void secondParse(int argc, char **argv);
void secondParse(QStringList);
public:
CmdLine();
......
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