aboutsummaryrefslogtreecommitdiff
path: root/src/clients/reconcilio/reconcilio.cc
blob: 3ff66731b70c02e888004d635afa4e8912c83c91 (plain)
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
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
159
160
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2007 Ciaran McCreesh <ciaran.mccreesh@blueyonder.co.uk>
 * Copyright (c) 2007 David Leverton <levertond@googlemail.com>
 *
 * This file is part of the Paludis package manager. Paludis is free software;
 * you can redistribute it and/or modify it under the terms of the GNU General
 * Public License version 2, as published by the Free Software Foundation.
 *
 * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "command_line.hh"
#include "fix_linkage.hh"

#include <paludis/util/join.hh>
#include <paludis/util/log.hh>

#include <paludis/about.hh>
#include <paludis/environment_maker.hh>
#include <paludis/args/do_help.hh>

#include <src/output/colour.hh>

#include <iostream>

using namespace paludis;

namespace
{
    struct DoVersion
    {
    };

    void display_version()
    {
        std::cout << "reconcilio, part of " << PALUDIS_PACKAGE << " " << PALUDIS_VERSION_MAJOR << "."
            << PALUDIS_VERSION_MINOR << "." << PALUDIS_VERSION_MICRO;
        if (! std::string(PALUDIS_SUBVERSION_REVISION).empty())
            std::cout << " svn " << PALUDIS_SUBVERSION_REVISION;
        std::cout << std::endl;
    }
}

int
main(int argc, char *argv[])
{
    Context ctx("In program " + join(argv, argv + argc, " ") + ":");

    try
    {
        CommandLine::get_instance()->run(argc, argv, "reconcilio", "RECONCILIO_OPTIONS", "RECONCILIO_CMDLINE");

        if (CommandLine::get_instance()->a_help.specified())
            throw args::DoHelp();
        if (CommandLine::get_instance()->a_version.specified())
            throw DoVersion();

        Log::get_instance()->set_program_name(argv[0]);
        if (CommandLine::get_instance()->a_log_level.specified())
            Log::get_instance()->set_log_level(CommandLine::get_instance()->a_log_level.option());

        set_use_colour(! CommandLine::get_instance()->a_no_colour.specified());

        std::string paludis_command("paludis");

        if (CommandLine::get_instance()->a_environment.specified())
            paludis_command.append(" --" + CommandLine::get_instance()->a_environment.long_name() + " " +
                    CommandLine::get_instance()->a_environment.argument());

        paludis_command.append(" --" + CommandLine::get_instance()->a_log_level.long_name() + " " +
                CommandLine::get_instance()->a_log_level.argument());

        if (CommandLine::get_instance()->a_resume_command_template.specified())
            paludis_command.append(" --" + CommandLine::get_instance()->a_resume_command_template.long_name() + " "
                    + CommandLine::get_instance()->a_resume_command_template.argument());

        if (CommandLine::get_instance()->a_no_color.specified())
            paludis_command.append(" --" + CommandLine::get_instance()->a_no_color.long_name());

        paludis_command.append(CommandLine::get_instance()->install_args.paludis_command_fragment());
        paludis_command.append(CommandLine::get_instance()->dl_args.paludis_command_fragment());

        tr1::shared_ptr<Environment> env(
            EnvironmentMaker::get_instance()->make_from_spec(
                CommandLine::get_instance()->a_environment.argument()));
        env->set_paludis_command(paludis_command);

        return do_fix_linkage(env);
    }

    catch (const DoVersion &)
    {
        display_version();
        std::cout << std::endl;
        std::cout << "Paludis comes with ABSOLUTELY NO WARRANTY. Paludis is free software, and you" << std::endl;
        std::cout << "are welcome to redistribute it under the terms of the GNU General Public" << std::endl;
        std::cout << "License, version 2." << std::endl;

        return EXIT_SUCCESS;
    }

    catch (const args::ArgsError & e)
    {
        std::cerr << "Usage error: " << e.message() << std::endl;
        std::cerr << "Try " << argv[0] << " --help" << std::endl;
        return EXIT_FAILURE;
    }

    catch (const args::DoHelp & h)
    {
        if (h.message.empty())
        {
            std::cout << "Usage: " << argv[0] << " [options]" << std::endl;
            std::cout << std::endl;
            std::cout << *CommandLine::get_instance();
            return EXIT_SUCCESS;
        }
        else
        {
            std::cerr << "Usage error: " << h.message << std::endl;
            std::cerr << "Try " << argv[0] << " --help" << std::endl;
            return EXIT_FAILURE;
        }
    }

    catch (const Exception & e)
    {
        std::cout << std::endl;
        std::cerr << "Unhandled exception:" << std::endl
                  << "  * " << e.backtrace("\n  * ")
                  << e.message() << " (" << e.what() << ")" << std::endl;
        return EXIT_FAILURE;
    }

    catch (const std::exception & e)
    {
        std::cout << std::endl;
        std::cerr << "Unhandled exception:" << std::endl
                  << "  * " << e.what() << std::endl;
        return EXIT_FAILURE;
    }

    catch (...)
    {
        std::cout << std::endl;
        std::cerr << "Unhandled exception:" << std::endl
                  << "  * Unknown exception type. Ouch..." << std::endl;
        return EXIT_FAILURE;
    }
}