[go: up one dir, main page]

Menu

[r189]: / tags / 0.10 / porg / main.cc  Maximize  Restore  History

Download this file

66 lines (50 with data), 1.5 kB

 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//=======================================================================
// main.cc - The main source file.
//-----------------------------------------------------------------------
// This file is part of the package porg
// Copyright (C) 2015 David Ricart
// For more information visit http://porg.sourceforge.net
//=======================================================================
#include "config.h"
#include "opt.h"
#include "logger.h"
#include "db.h"
#include "main.h"
using namespace Porg;
// Initialization of global vars
int Porg::g_exit_status = EXIT_SUCCESS;
int main(int argc, char* argv[])
{
std::ios::sync_with_stdio(false);
try
{
Opt::init(argc, argv);
if (Opt::mode() == MODE_LOG) {
Logger::run();
return g_exit_status;
}
DB db;
if (Opt::mode() == MODE_QUERY || Opt::all_pkgs())
db.get_pkgs_all();
else
db.get_pkgs(Opt::args());
if (db.empty())
return g_exit_status;
db.sort_pkgs(Opt::sort_type(), Opt::reverse_sort());
switch (Opt::mode()) {
case MODE_CONF_OPTS: db.print_conf_opts(); break;
case MODE_INFO: db.print_info(); break;
case MODE_LIST_PKGS: db.list_pkgs(); break;
case MODE_LIST_FILES: db.list_files(); break;
case MODE_REMOVE: db.remove(); break;
case MODE_QUERY: db.query(); break;
default: assert(0); break;
}
}
catch (std::exception const& x)
{
std::cerr << "porg: " << x.what() << '\n';
g_exit_status = EXIT_FAILURE;
}
return g_exit_status;
}