This example demonstrates how to use actions. It uses FetchAction to fetch source files for all versions of sys-apps/paludis that support fetching.
#include <iostream>
#include <cstdlib>
using namespace paludis;
using namespace examples;
using std::cout;
using std::endl;
namespace
{
std::shared_ptr<OutputManager> make_standard_output_manager(
const Action &)
{
return std::make_shared<StandardOutputManager>();
}
WantPhase want_all_phases(
const std::string &)
{
}
}
int main(int argc, char * argv[])
{
int exit_status(0);
try
{
CommandLine::get_instance()->run(argc, argv,
"example_action", "EXAMPLE_ACTION_OPTIONS", "EXAMPLE_ACTION_CMDLINE");
CommandLine::get_instance()->a_environment.argument()));
i != i_end ; ++i)
{
if (! (*i)->supports_action(supports_fetch_action))
{
cout << "ID '" << **i << "' does not support the fetch action." << endl;
}
else
{
cout << "ID '" << **i << "' supports the fetch action, trying to fetch:" << endl;
FetchAction fetch_action(make_named_values<FetchActionOptions>(
));
try
{
(*i)->perform_action(fetch_action);
}
{
exit_status |= 1;
cout << "Caught FetchActionError, with the following details:" << endl;
f != f_end ; ++f)
{
cout << " * File '" << f->target_file() << "': ";
bool need_comma(false);
if (f->requires_manual_fetching())
{
cout << "requires manual fetching";
need_comma = true;
}
if (f->failed_automatic_fetching())
{
if (need_comma)
cout << ", ";
cout << "failed automatic fetching";
need_comma = true;
}
if (! f->failed_integrity_checks().empty())
{
if (need_comma)
cout << ", ";
cout << "failed integrity checks: " << f->failed_integrity_checks();
need_comma = true;
}
}
cout << endl;
}
}
cout << endl;
}
}
{
cout << endl;
cout << "Unhandled exception:" << endl
return EXIT_FAILURE;
}
catch (const std::exception & e)
{
cout << endl;
cout << "Unhandled exception:" << endl
<< " * " << e.what() << endl;
return EXIT_FAILURE;
}
catch (...)
{
cout << endl;
cout << "Unhandled exception:" << endl
<< " * Unknown exception type. Ouch..." << endl;
return EXIT_FAILURE;
}
return exit_status;
}