main.cpp 4.62 KB
Newer Older
1
/* This file is part of the Chakra project
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
   Copyright (C) 2011 Lukas Appelhans <l.appelhans@gmx.de>

   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 <kcmdlineargs.h>
#include <klocalizedstring.h>
#include <kuniqueapplication.h>
#include <kaboutdata.h>
#include <kdebug.h>
#include "apm.h"

int main(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 options;
Lukas Appelhans's avatar
Lukas Appelhans committed
30 31 32 33
    
    options.add("D", ki18n("Database operation"));
    
    options.add("Q", ki18n("Query operation"));
34 35 36 37 38 39 40 41 42 43 44 45 46
    options.add("c", ki18n("Shows changelog of the package"));
    options.add("d", ki18n("Shows packages which got installed as dependencies"));
    options.add("e", ki18n("Shows packages which got installed explicitely"));
    options.add("g", ki18n("Shows all packages in a package group"));
    options.add("i", ki18n("Shows package information"));
    options.add("k", ki18n("Check if the files of the package are available"));
    options.add("m", ki18n("Shows packages which were not found in the Sync-db(s)"));
    options.add("o", ki18n("Returns the package which contains the file"));
    options.add("p", ki18n("Queries a package file instead of the database"));
    options.add("s", ki18n("Searches locally installed packages"));
    options.add("t", ki18n("Returns packages who are not required by others"));
    options.add("u", ki18n("Returns upgradable packages"));
    options.add("q", ki18n("Shows less information in queries and searches"));
Lukas Appelhans's avatar
Lukas Appelhans committed
47 48 49
    
    options.add("R", ki18n("Remove operation"));
    
50 51 52
    options.add("S", ki18n("Sync operation"));
    options.add("y", ki18n("Refresh database"));
    options.add("u", ki18n("Update system"));
Lukas Appelhans's avatar
Lukas Appelhans committed
53 54
    
    options.add("U", ki18n("Upgrade operation"));
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72

    KCmdLineArgs::addCmdLineOptions(options);

    // Add options from other components
    KUniqueApplication::addCmdLineOptions();
    
    if (!KUniqueApplication::start()) {
       fprintf(stderr, "Akabei is already running!\n");
       return 0;
    }
    
    KUniqueApplication app;

    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
    
    QList<APM::Operation> list;
    APM::OperationType type = APM::NoType;
    
Lukas Appelhans's avatar
Lukas Appelhans committed
73 74 75 76
    if (args->isSet("D")) {
        type = APM::DatabaseOperation;
    } else if (args->isSet("Q")) {
        type = APM::QueryOperation;
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
        if (args->isSet("c"))
            list.append(APM::ShowChangelog);
        if (args->isSet("d"))
            list.append(APM::ShowInstalledAsDeps);
        if (args->isSet("e"))
            list.append(APM::ShowInstalledExplicitely);
        if (args->isSet("g"))
            list.append(APM::ShowPackagesOfGroup);
        if (args->isSet("i"))
            list.append(APM::ShowInformation);
        if (args->isSet("k"))
            list.append(APM::CheckFiles);
        if (args->isSet("m"))
            list.append(APM::ShowLocal);
        if (args->isSet("o"))
            list.append(APM::ShowOwner);
        if (args->isSet("p"))
            list.append(APM::QueryPackageFile);
        if (args->isSet("s"))
            list.append(APM::SearchLocal);
        if (args->isSet("t"))
            list.append(APM::ShowNotRequired);
        if (args->isSet("u"))
            list.append(APM::ShowUpgradeable);
        if (args->isSet("q"))
            list.append(APM::ShowLess);
Lukas Appelhans's avatar
Lukas Appelhans committed
103 104 105
    } else if (args->isSet("R")) {
        type = APM::RemoveOperation;
    } else if (args->isSet("S")) {
106 107 108
        type = APM::SyncOperation;
        if (args->isSet("y"))
            list.append(APM::UpdateDatabases);
Lukas Appelhans's avatar
Lukas Appelhans committed
109
        if (args->isSet("u"))
110
            list.append(APM::UpdateSystem);
Lukas Appelhans's avatar
Lukas Appelhans committed
111 112 113 114 115
    } else if (args->isSet("U")) {
        type = APM::UpgradeOperation;
    } else {
       fprintf(stderr, "Please select an operation to do!\nCall akabei --help for explanation.\n");
       return app.exec();
116 117 118 119
    }
    
    QStringList rest;

Lukas Appelhans's avatar
Lukas Appelhans committed
120
    for (int i = 0; i < args->count(); i++) {
121 122 123 124 125
       rest << args->arg(i);
    }
     
    args->clear(); // Free up some memory
    
126
    APM apm(type, list, rest);
127 128

    return app.exec();
129
}