This example demonstrates how to use PackageID.
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <set>
using namespace paludis;
using namespace examples;
using std::cout;
using std::endl;
using std::left;
using std::setw;
using std::hex;
using std::boolalpha;
int main(int argc, char * argv[])
{
int exit_status(0);
try
{
CommandLine::get_instance()->run(argc, argv,
"example_package_id", "EXAMPLE_PACKAGE_ID_OPTIONS", "EXAMPLE_PACKAGE_ID_CMDLINE");
CommandLine::get_instance()->a_environment.argument()));
i != i_end ; ++i)
{
cout << **i << ":" << endl;
cout << left << setw(30) << " Name:" << " " << (*i)->name() << endl;
cout << left << setw(30) << " Version:" << " " << (*i)->version() << endl;
cout << left << setw(30) << " Repository Name:" << " " << (*i)->repository_name() << endl;
cout << left << setw(30) <<
" idcf_full:" <<
" " << (*i)->canonical_form(
idcf_full) << endl;
cout << left << setw(30) <<
" idcf_version:" <<
" " << (*i)->canonical_form(
idcf_version) << endl;
cout << left << setw(30) <<
" idcf_no_version:" <<
" " << (*i)->canonical_form(
idcf_no_version) << endl;
cout << left << setw(30) <<
" idcf_no_name:" <<
" " << (*i)->canonical_form(
idcf_no_name) << endl;
cout << left << setw(30) << " Keys:" << " " << endl;
for (PackageID::MetadataConstIterator k((*i)->begin_metadata()), k_end((*i)->end_metadata()) ;
k != k_end ; ++k)
cout << left << setw(30) << (" " + (*k)->raw_name() + ":") << " " << (*k)->human_name() << endl;
if ((*i)->masked())
{
cout << left << setw(30) << " Masks:" << " " << endl;
m != m_end ; ++m)
cout << left << setw(30) << (
" " +
stringify((*m)->key()) +
":") <<
" " << (*m)->description() << endl;
}
std::set<std::string> actions;
{
if ((*i)->supports_action(install_action))
actions.insert("install");
if ((*i)->supports_action(uninstall_action))
actions.insert("uninstall");
if ((*i)->supports_action(pretend_action))
actions.insert("pretend");
if ((*i)->supports_action(config_action))
actions.insert("config");
if ((*i)->supports_action(fetch_action))
actions.insert("fetch");
if ((*i)->supports_action(info_action))
actions.insert("info");
}
cout << left << setw(30) <<
" Actions:" <<
" " <<
join(actions.begin(), actions.end(),
" ") << endl;
std::shared_ptr<const Set<std::string> > breaks_portage((*i)->breaks_portage());
cout << left << setw(30) <<
" breaks_portage:" <<
" " <<
join(breaks_portage->begin(),
breaks_portage->end(), ", ") << endl;
cout << left << setw(30) << " extra_hash_value:" << " " << "0x" << hex << (*i)->extra_hash_value() << 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;
}