cmdline.cpp 22 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
/* This file is part of the Chakra project

   Copyright (C) 2011 Lisa "shainer" Vitolo <shainer@chakra-project.org>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.
*/

#include "cmdline.h"

#include <kaboutdata.h>
#include <klocalizedstring.h>
#include <QDebug>

/*
 * Build our database of accepted operations and options with the right properties and associations
 */
CmdLine::CmdLine()
: parsed(false)
{
    typechars.insert("D", APM::DatabaseOperationType);
    typechars.insert("Q", APM::QueryOperationType);
    typechars.insert("R", APM::RemoveOperationType);
    typechars.insert("S", APM::SyncOperationType);
    typechars.insert("U", APM::UpgradeOperationType);
    
    /*
     * The argument list is only meaningful after reading the command line, so for now it stays empty
     */
    AkabeiOption querypkgfile(APM::QueryPackageFile, "p", "file", "Queries a package file instead of the database", true);
    AkabeiOption showlocal(APM::ShowLocal, "m", "foreign", "Shows packages which were not found in the Sync-db(s)", false);
    AkabeiOption showless(APM::ShowLess, "q", "quiet", "Shows less information in queries and searches", false);
    AkabeiOption installasdeps(APM::InstallAsDeps, "", "asdeps", "Install all packages as non-explicit", false);
    AkabeiOption installasexplicit(APM::InstallAsExplicit, "", "asexplicit", "APM::Install all packages as explicit", false);
    AkabeiOption skipdependencycheck(APM::SkipDependencyCheck, "w", "nodeps", "Skip dependency check", false);
    AkabeiOption force(APM::Force, "f", "force", "Force installation. Overwrite file conflicts", false);
    AkabeiOption downloadonly(APM::DownloadOnly, "d", "downloadonly", "Downloads packages without installing or upgrading them", false);
    AkabeiOption onlyneeded(APM::OnlyNeeded, "", "needed", "Up-to-date packages are not reinstalled", false);
    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);
Lisa's avatar
Lisa committed
44
    AkabeiOption removeconfig(APM::RemoveConfig, "n", "nsave", "Also remove configuration files", false);
45 46 47 48 49 50 51 52 53
    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);
    AkabeiOption dbpath(APM::DBPath, "b", "dbpath", "Set a different database dir", false);
    
    acceptedOptions << querypkgfile << showlocal << showless << installasdeps << installasexplicit << skipdependencycheck;
    acceptedOptions << force << downloadonly << onlyneeded << ignore << ignoregroup << databaseonly << removeconfig << recursive;
    acceptedOptions << rootdir << cachedir << dbpath;
    
Lisa's avatar
Lisa committed
54
    AkabeiOperation database(APM::DatabaseOperationType, APM::DatabaseOperation, "D", "", "Database operation", false);
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
    
    AkabeiOperation changelog(APM::QueryOperationType, APM::ShowChangelog, "c", "changelog", "Shows changelog of the package", true);
    changelog.addOption(querypkgfile);
    
    AkabeiOperation installedasdeps(APM::QueryOperationType, APM::ShowInstalledAsDeps, "d", "deps", "Shows packages which got installed as dependencies", false);
    installedasdeps.addOption(querypkgfile);
    installedasdeps.addOption(ignore);
    installedasdeps.addOption(ignoregroup);
    
    AkabeiOperation installedexp(APM::QueryOperationType, APM::ShowInstalledExplicitely, "e", "explicit", "Shows packages which got installed explicitely", false);
    installedexp.addOption(querypkgfile);
    installedexp.addOption(ignore);
    installedexp.addOption(ignoregroup);
    
    AkabeiOperation checkfiles(APM::QueryOperationType, APM::CheckFiles, "k", "check", "Check if the files of the package are available", true);
    checkfiles.addOption(querypkgfile);
    checkfiles.addOption(showlocal);
    
    AkabeiOperation showowner(APM::QueryOperationType, APM::ShowOwner, "o", "owns", "Returns the package which contains the file", true);
    showowner.addOption(querypkgfile);
    showowner.addOption(showlocal);
    
    AkabeiOperation notrequired(APM::QueryOperationType, APM::ShowNotRequired, "t", "unrequired", "Returns packages which are not required by others", false);
    notrequired.addOption(querypkgfile);
    notrequired.addOption(ignore);
    notrequired.addOption(ignoregroup);
    
    AkabeiOperation upgradeable(APM::QueryOperationType, APM::ShowUpgradeable, "u", "upgrades", "Returns upgradeable packages", false);
    upgradeable.addOption(querypkgfile);
    upgradeable.addOption(ignore);
    upgradeable.addOption(ignoregroup);
    
    AkabeiOperation groupsl(APM::QueryOperationType, APM::ShowPackagesOfGroupLocal, "g", "groups", "Shows all packages in a package group", true);
    groupsl.addOption(ignore);
    
    AkabeiOperation infol(APM::QueryOperationType, APM::ShowInformationLocal, "i", "info", "Shows package information", true);
    infol.addOption(showless);
    
    AkabeiOperation searchl(APM::QueryOperationType, APM::SearchLocal, "s", "search", "Searches repositories for a word", true);
    searchl.addOption(ignore);
    searchl.addOption(ignoregroup);
    
    AkabeiOperation remove(APM::RemoveOperationType, APM::Remove, "R", "remove", "Remove packages", true);
    remove.addOption(skipdependencycheck);
    remove.addOption(force);
    remove.addOption(databaseonly);
    remove.addOption(removeconfig);
    remove.addOption(recursive);
    
    AkabeiOperation cascade(APM::RemoveOperationType, APM::Cascade, "c", "cascade", "Remove packages with their dependencies", true);
    
    AkabeiOperation unneeded(APM::RemoveOperationType, APM::Unneeded, "u", "unneeded", "Remove not needed packages", false);
    unneeded.addOption(ignore);
    unneeded.addOption(ignoregroup);
    
    AkabeiOperation install(APM::SyncOperationType, APM::Install, "S", "install", "Install packages", true);
    install.addOption(installasdeps);
    install.addOption(installasexplicit);
    install.addOption(skipdependencycheck);
    install.addOption(force);
    install.addOption(downloadonly);
    install.addOption(onlyneeded);

    AkabeiOperation removeold(APM::SyncOperationType, APM::RemoveOldFromCache, "c", "clean", "Remove old packages from cache", false);
    
    AkabeiOperation removeallcache(APM::SyncOperationType, APM::RemoveAllCache, "cc", "", "Remove all packages from cache", false);
    
    AkabeiOperation groups(APM::SyncOperationType, APM::ShowPackagesOfGroup, "g", "groups", "Shows all packages in a package group", true);
    groups.addOption(ignore);
    
    AkabeiOperation info(APM::SyncOperationType, APM::ShowInformation, "i", "info", "Shows package information", true);
    info.addOption(showless);
    
    AkabeiOperation search(APM::SyncOperationType, APM::Search, "s", "search", "Searches repositories for a word", true);
    search.addOption(ignore);
    search.addOption(ignoregroup);
    
    AkabeiOperation listrepo(APM::SyncOperationType, APM::ListRepo, "l", "list", "List all packages in a repository", true);
    listrepo.addOption(querypkgfile);
    listrepo.addOption(showlocal);
    listrepo.addOption(ignore);
    listrepo.addOption(ignoregroup);
    
    AkabeiOperation updatedb(APM::SyncOperationType, APM::UpdateDatabases, "y", "refresh", "Refresh database", false);
    
    AkabeiOperation updatesys(APM::SyncOperationType, APM::UpdateSystem, "u", "sysupgrade", "Update system", false);
    updatesys.addOption(downloadonly);
    updatesys.addOption(ignore);
    updatesys.addOption(ignoregroup);
    
    AkabeiOperation updatedbandsys(APM::SyncOperationType, APM::UpdateDatabaseAndSystem, "", "", "Refresh database and update system", false);
    updatedbandsys.addOption(downloadonly);
    updatedbandsys.addOption(ignore);
    updatedbandsys.addOption(ignoregroup);
    
    AkabeiOperation upgrade(APM::UpgradeOperationType, APM::Upgrade, "U", "", "Upgrade operation", true);
    upgrade.addOption(downloadonly);
    upgrade.addOption(ignore);
    upgrade.addOption(ignoregroup);
    
    AkabeiOperation help(APM::NoType, APM::Help, "h", "help", "Shows the help message", false);
    
    AkabeiOperation version(APM::NoType, APM::Version, "v", "version", "Shows Akabei version", false);
    
Lisa's avatar
Lisa committed
159 160 161 162 163
    AkabeiOperationList tmp;
    tmp << removeallcache << help << version << install << remove << database << changelog << installedasdeps << installedexp;
    tmp << checkfiles << showowner << notrequired << upgradeable << cascade;
    tmp << removeold << groups << info << listrepo << groupsl << searchl << infol;
    tmp << search << updatedb << updatesys << updatedbandsys << upgrade;
164
    
Lisa's avatar
Lisa committed
165 166 167 168
    /* 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) {
169 170 171 172 173
        /* These options are associated to every operation */
        op.addOption(rootdir);
        op.addOption(cachedir);
        op.addOption(dbpath);
        
Lisa's avatar
Lisa committed
174
        acceptedOperations.insertMulti(op.type, op);      
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
    }
}

AkabeiOption::AkabeiOption(APM::OptionName n, const char *cs, const char *cl, const char *desc, bool hasArg)
{
    QStringList unused;
    init(n, cs, cl, desc, hasArg, unused);
}

AkabeiOption::AkabeiOption(APM::OptionName n, const char *cs, const char *cl, const char *desc, bool hasArg, QStringList a)
{
    init(n, cs, cl, desc, hasArg, a);
}

void AkabeiOption::init(APM::OptionName n, const char *cs, const char *cl, const char *desc, bool hasArg, QStringList a)
{
    name = n;
    commandShort = QString::fromAscii(cs).toUtf8();
    commandLong = QString::fromAscii(cl).toUtf8();
    description = ki18n(desc);
    this->hasArg = hasArg;
    this->args = a;
}

AkabeiOperation::AkabeiOperation(APM::OperationType t, APM::OperationName n, const char *cs, const char *cl, const char *desc, bool hasFreeArgs)
{
    QStringList args;
    init(t, n, cs, cl, desc, hasFreeArgs, args);
}

AkabeiOperation::AkabeiOperation(APM::OperationType t, APM::OperationName n, const char *cs, const char *cl, const char *desc, bool hasFreeArgs, QStringList args)
{
    init(t, n, cs, cl, desc, hasFreeArgs, args);
}

AkabeiOperation::AkabeiOperation()
{
    init(APM::NoType, APM::None, "", "", "", false, QStringList());
}

/*
Lisa's avatar
Lisa committed
216
 * This requires some explanation
217 218 219 220 221 222 223 224 225 226
 * 
 * 0: APM::None means no operation has still been set, so no problem here.
 * 1: -S is Install, but for example -Ss is Search. Same for most removing operations. This overlapping is fine.
 * 2: the elements in a hash aren't sorted, so "s" may be found before "S".
 * 3: for -Scc, both "cc" and "c" are found. Only the first one is good.
 * 4: -Sy is UpdateDatabases, -Su is UpdateSystem, but -Syu is APM::UpdateDatabaseAndSystem (only linked operations accepted).
 * 5: All the rest is invalid
 */
void AkabeiOperation::set(AkabeiOperation& other)
{
Lisa's avatar
Lisa committed
227
    if ((this->type == APM::SyncOperationType && other.name == APM::Install) || (this->type == APM::RemoveOperationType && other.name == APM::Remove)) {
228 229 230
        return;
    }
    
Lisa's avatar
Lisa committed
231
    if (this->name == APM::None || this->name == APM::Remove || this->name == APM::Install || (this->commandShort == "c" && other.name == APM::RemoveAllCache)) {
232 233 234
        this->name = other.name;
        this->type = other.type;
        this->options = other.options;
235 236
        this->commandLong = other.commandLong;
        this->commandShort = other.commandShort;
237 238 239 240 241 242
        this->hasFreeArgs = other.hasFreeArgs;
    } else if ((this->name == APM::UpdateDatabases && other.name == APM::UpdateSystem) || (this->name == APM::UpdateSystem && other.name == APM::UpdateDatabases)) {
        this->name = APM::UpdateDatabaseAndSystem;
        this->type = APM::SyncOperationType;
        this->hasFreeArgs = false;
    } else {
Lisa's avatar
Lisa committed
243
        throw CmdLineException("multiple operations present.");
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
    }
}

void AkabeiOperation::init(APM::OperationType t, APM::OperationName n, const char *cs, const char *cl, const char *desc, bool hasFreeArgs, QStringList args)
{
    type = t;
    name = n;
    commandShort = QString::fromAscii(cs).toUtf8();
    commandLong = QString::fromAscii(cl).toUtf8();
    description = ki18n(desc);
    this->hasFreeArgs = hasFreeArgs;
    this->freeArgs = args;
}

void AkabeiOperation::addOption(AkabeiOption& opt)
{
    options.insert(opt.name, opt);
}

bool AkabeiOperation::isOptionSupported(APM::OptionName name)
{
    return options.contains(name);
}

/*
 * Actual parsing
 */
void CmdLine::parse(int argc, char** argv)
{
    KAboutData aboutData("akabei", 0, ki18n("Akabei"),
                         QByteArray("0.0.1"),
                         ki18n("Chakra's CLI package manager"),
                         KAboutData::License_GPL,
                         ki18n("(C) 2011 Lukas Appelhans"),
                         ki18n("<a href=\"mailto:boom1992@chakra-project.org\">boom1992@chakra-project.org</a>"));
    
    aboutData.addAuthor(ki18n("Lukas Appelhans"), ki18n("Maintainer"), "boom1992@chakra-project.org");
    KCmdLineArgs::init(argc, argv, &aboutData);
    KCmdLineOptions koptions;
    
    /*
Lisa's avatar
Lisa committed
285
     * Adds the only type which is not an operation
286
     */
Lisa's avatar
Lisa committed
287
    koptions.add("Q", ki18n("Query operation"));
288 289 290 291
    
    /*
     * Adds all the operations
     */
Lisa's avatar
Lisa committed
292
    foreach (AkabeiOperation op, acceptedOperations.values()) {
Lisa's avatar
Lisa committed
293 294 295
        if (!op.commandShort.isEmpty()) {
            if (!op.commandLong.isEmpty()) {
                koptions.add(op.commandLong);
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
            }
            koptions.add(op.commandShort, op.description);
        }
    }
    
    /*
     * Adds all the option with <argument> if they require one
     * TODO: make <argument> more explicative of its nature (package, group, filename, ...)
     */
    foreach (AkabeiOption opt, acceptedOptions) {
        QByteArray newcomlong = opt.commandLong;
        if (opt.hasArg) {
            newcomlong += " <argument>";
        }
        if (!opt.commandShort.isEmpty()) {
            koptions.add(opt.commandShort);
        }
        koptions.add(newcomlong, opt.description);
    }
    
    /*
     * Free arguments at the end
     */
    koptions.add("+[arg1]", ki18n("An optional argument 'arg1'"));
    
    /*
     * Parsing!
     */
    KCmdLineArgs::addCmdLineOptions(koptions);
    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
    
    APM::OperationType type = APM::NoType;
    m_operation.name = APM::None;
Lisa's avatar
Lisa committed
329
    QList<QByteArray> found;
330 331 332 333 334
    
    /*
     * These are considered separately and when found, they surpass any other operation that may be present.
     */
    if (args->isSet("h")) {
Lisa's avatar
Lisa committed
335 336
        AkabeiOperation help = specialOperations[1];
        m_operation.set(help);
337
    } else if (args->isSet("v")) {
Lisa's avatar
Lisa committed
338 339
        AkabeiOperation version = specialOperations[2];
        m_operation.set(version);
340 341 342 343 344
    }
    else {
        for (QHash<QByteArray, APM::OperationType>::iterator it = typechars.begin(); it != typechars.end(); it++) {
            if (args->isSet(it.key())) {
                if (type != APM::NoType) {
345
                    throw CmdLineException("multiple types present.");
346 347 348 349
                }
                type = it.value();
            
                /*
Lisa's avatar
Lisa committed
350 351
                 * We look only for the acceptable operations
                 * all the others, if present, will be spotted later
352
                 */
Lisa's avatar
Lisa committed
353 354 355 356 357 358
                foreach (AkabeiOperation op, acceptedOperations.values(type)) {
                    /*
                     * This eliminates the only "dummy" operation with no commands at all
                     * every other operation has got at least the short command
                     */
                    if (op.commandShort.isEmpty()) {
359 360 361 362
                        continue;
                    }
                    
                    /*
Lisa's avatar
Lisa committed
363
                     * Saves up the commands for later inspection
364
                     */
Lisa's avatar
Lisa committed
365 366 367 368 369
                    if (args->isSet(op.commandShort)) {
                        m_operation.set(op);
                        found << op.commandShort;
                        if (!op.commandLong.isEmpty()) {
                            found << op.commandLong;
370 371 372
                        }
                    }
                }
Lisa's avatar
Lisa committed
373 374 375 376 377 378 379 380 381 382
                
                /*
                 * This kind of command is unfortunately completely ignored (-S -cc is fine)
                 * so we have to check it separately. Again, malformed versions will be spotted later
                 */
                if (KCmdLineArgs::allArguments().contains("-Scc")) {
                    AkabeiOperation special = specialOperations.first();
                    m_operation.set(special);
                    found << special.commandShort;
                }
383 384 385 386 387
            }
        }
    }
    
    if (m_operation.name == APM::None) {
388
        throw CmdLineException("no operation specified.");
389 390 391 392 393 394
    }
    
    foreach (AkabeiOption opt, acceptedOptions) {
        QByteArray command = (opt.commandShort.isEmpty()) ? opt.commandLong : opt.commandShort;
        
        /* 
Lisa's avatar
Lisa committed
395
         * If "found" contains the command, we it was an operation, so go on
396
         */
Lisa's avatar
Lisa committed
397
        if (!found.contains(command) && args->isSet(command)) {            
398
            if (!m_operation.isOptionSupported(opt.name)) {
399
                throw CmdLineException("invalid option for this operation");
400 401 402 403 404 405 406 407 408 409 410 411
            }
            
            /*
             * Gets arguments associated with the option
             */
            QStringList optargs = args->getOptionList(command);

            /*
             * Remember, if it's not an option args it can be an argument to the operation
             * so we're not really sure an error has been made, unless the operation doesn't admit any argument
             */
            if (!optargs.isEmpty() && !opt.hasArg && !m_operation.hasFreeArgs) {
412 413
                QString message = "the option \"" + command + "\" must not have an argument.";
                throw CmdLineException(message.toUtf8().data());
414 415 416 417 418 419
            }
            
            /*
             * In this case, we're sure :)
             */
            if (optargs.isEmpty() && opt.hasArg) {
420 421
                QString message = "missing argument for the option \"" + command + "\"";
                throw CmdLineException(message.toUtf8().data());
422 423 424 425 426 427 428 429
            }
            
            opt.args = optargs;
            m_options.insert(opt.name, opt);
        }
    }
    
    /*
Lisa's avatar
Lisa committed
430
     * Gets all the other arguments around
431 432 433 434 435 436
     */
    for (int i = 0; i < args->count(); i++) {
        m_freeArgs << args->arg(i);
    }
    
    if (!m_freeArgs.isEmpty() && !m_operation.hasFreeArgs) {
437
        throw CmdLineException("unexpected free arguments.");
438 439 440
    }
    
    if (m_freeArgs.isEmpty() && m_operation.hasFreeArgs) {
441
        throw CmdLineException("free arguments required but not present.");
442 443 444
    }
    
    args->clear(); /* frees up memory */
445
    
Lisa's avatar
Lisa committed
446
    secondParse(KCmdLineArgs::allArguments(), found);
447 448 449
    parsed = true;
}

450
/*
Lisa's avatar
Lisa committed
451 452 453 454
 * This function handles all the parsing which can't be handled before
 * In particular, checks
 * * if the operation is repeated more than once (not accepted)
 * * if there's something "out of context" in the command line (like, some meaningless command)
455
 */
Lisa's avatar
Lisa committed
456
void CmdLine::secondParse(QStringList args, QList<QByteArray> foundCmds)
457
{
Lisa's avatar
Lisa committed
458
    QList<QByteArray> cmdline;
459
    
Lisa's avatar
Lisa committed
460
    foreach (QString part, args) {
461 462 463 464
        if (part.size() < 2) {
            continue;
        }
        
Lisa's avatar
Lisa committed
465
        /* Long command */
466
        if (part.at(0) == '-' && part.at(1) == '-') {
Lisa's avatar
Lisa committed
467 468
            cmdline << part.remove(0, 2).toUtf8();
        /* Short command: takes each letter separately */
469 470 471 472 473 474 475 476 477
        } else if (part.at(0) == '-') {
            part.remove(0, 1);
            
            /* The only short commands with two letters is treated separately to avoid problems */
            if (part.contains("cc")) {
                if (part.count("cc") > 1) {
                    throw CmdLineException("can't accept linked operations.");
                } else {
                    part.remove("cc");
Lisa's avatar
Lisa committed
478
                    cmdline << "cc";
479 480 481 482
                }
            }
            
            for (int ch = 0; ch < part.length(); ch++) {
Lisa's avatar
Lisa committed
483 484
                QString tmp(part[ch]);
                cmdline << tmp.toUtf8();
485 486 487 488
            }
        }
    }
    
Lisa's avatar
Lisa committed
489 490 491 492 493 494 495 496 497 498 499 500 501
    /*
     * If the command line contains something else other than what we have already parsed
     * there's something wrong around
     */
    foreach (QByteArray com, cmdline) {
        if (!foundCmds.contains(com)) {
            throw CmdLineException("Out of context operation");
        }
    }
    
    /*
     * Counts the occurrence of the operation
     */
502 503 504 505 506
    int occurrences = cmdline.count(m_operation.commandLong) + cmdline.count(m_operation.commandShort);
    if (occurrences > 1) {
        throw CmdLineException("can't accept linked operations.");
    }
    
Lisa's avatar
Lisa committed
507 508 509
    /*
     * Counts the occurrence of all the options we previously found
     */
510 511 512 513 514 515 516 517 518
    foreach (AkabeiOption opt, m_options.values()) {
        
        /* The only options allowed to be repeated several times */
        if (opt.name == APM::Ignore || opt.name == APM::IgnoreGroup) {
            continue;
        }
        
        occurrences = cmdline.count(opt.commandLong) + cmdline.count(opt.commandShort);
        if (occurrences > 1) {
Lisa's avatar
Lisa committed
519
            throw CmdLineException("can't repeat this option twice.");
520 521 522 523
        }
    }
}

524 525 526 527 528
APM::OperationType CmdLine::type()
{
    if (!parsed) {
        throw CmdLineException("Command line not parsed.");
    }
529

530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
    return m_operation.type;
}

APM::OperationName CmdLine::operation()
{
    if (!parsed) {
        throw CmdLineException("Command line not parsed.");
    }
    
    return m_operation.name;
}

QStringList CmdLine::freeArgs()
{
    if (!parsed) {
        throw CmdLineException("Command line not parsed.");
    }
    
    return m_freeArgs;
}

QHash< APM::OptionName, AkabeiOption > CmdLine::options()
{
    if (!parsed) {
        throw CmdLineException("Command line not parsed.");
    }
    
    return m_options;
}