summaryrefslogtreecommitdiff
path: root/main.cc
blob: 08a50926e3c9f8113e27b24cd7d58c876f3396e4 (plain)
    1 //
    2 //  pkgutils
    3 // 
    4 //  Copyright (c) 2000-2005 Per Liden
    5 //  Copyright (c) 2006-2021 by CRUX team (http://crux.nu)
    6 // 
    7 //  This program is free software; you can redistribute it and/or modify
    8 //  it under the terms of the GNU General Public License as published by
    9 //  the Free Software Foundation; either version 2 of the License, or
   10 //  (at your option) any later version.
   11 //
   12 //  This program is distributed in the hope that it will be useful,
   13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
   14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15 //  GNU General Public License for more details.
   16 //
   17 //  You should have received a copy of the GNU General Public License
   18 //  along with this program; if not, write to the Free Software
   19 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
   20 //  USA.
   21 //
   22 
   23 #if (__GNUC__ < 3)
   24 #error This program requires GCC 3.x to compile.
   25 #endif
   26 
   27 #include <iostream>
   28 #include <string>
   29 #include <memory>
   30 #include <cstdlib>
   31 #include <libgen.h>
   32 #include "pkgutil.h"
   33 #include "pkgadd.h"
   34 #include "pkgrm.h"
   35 #include "pkginfo.h"
   36 
   37 using namespace std;
   38 
   39 static pkgutil* select_utility(const string& name)
   40 {
   41 	if (name == "pkgadd")
   42 		return new pkgadd;
   43 	else if (name == "pkgrm")
   44 		return new pkgrm;
   45 	else if (name == "pkginfo")
   46 		return new pkginfo;
   47 	else
   48 		throw runtime_error("command not supported by pkgutils");
   49 }
   50 
   51 int main(int argc, char** argv)
   52 {
   53 	string name = basename(argv[0]);
   54 
   55 	try {
   56 		unique_ptr<pkgutil> util(select_utility(name));
   57 
   58 		// Handle common options
   59 		for (int i = 1; i < argc; i++) {
   60 			string option(argv[i]);
   61 			if (option == "-v" || option == "--version") {
   62 				util->print_version();
   63 				return EXIT_SUCCESS;
   64 			} else if (option == "-h" || option == "--help") {
   65 				util->print_help();
   66 				return EXIT_SUCCESS;
   67 			}
   68 		}
   69 
   70 		util->run(argc, argv);
   71 	} catch (runtime_error& e) {
   72 		cerr << name << ": " << e.what() << endl;
   73 		return EXIT_FAILURE;
   74 	}
   75 
   76 	return EXIT_SUCCESS;
   77 }

Generated by cgit