aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-17 00:27:43 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-01-17 00:27:43 +0000
commit103e5770f120d70b1580bfc3cab8219c6608bc21 (patch)
tree55d04f6fbf26db1698fb12264ac3b86c40455187 /src
downloadpaludis-103e5770f120d70b1580bfc3cab8219c6608bc21.tar.gz
paludis-103e5770f120d70b1580bfc3cab8219c6608bc21.tar.xz
Initial import
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am21
-rw-r--r--src/colour.cc22
-rw-r--r--src/colour.hh57
-rw-r--r--src/command_line.cc59
-rw-r--r--src/command_line.hh137
-rw-r--r--src/install.cc168
-rw-r--r--src/install.hh33
-rw-r--r--src/list_repositories.cc49
-rw-r--r--src/list_repositories.hh31
-rw-r--r--src/paludis.cc160
-rw-r--r--src/query.cc169
-rw-r--r--src/query.hh33
12 files changed, 939 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 000000000..446f54018
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,21 @@
+CLEANFILES = *~
+MAINTAINERCLEANFILES = Makefile.in
+AM_CXXFLAGS = -I$(top_srcdir)
+DEFS=-DSYSCONFDIR=\"$(sysconfdir)\"
+
+bin_PROGRAMS = paludis
+
+paludis_SOURCES = \
+ command_line.hh command_line.cc \
+ colour.hh colour.cc \
+ install.hh install.cc \
+ list_repositories.hh list_repositories.cc \
+ query.hh query.cc \
+ paludis.cc
+
+paludis_LDADD = \
+ $(top_builddir)/paludis/libpaludis.a \
+ $(top_builddir)/paludis/args/libpaludisargs.a
+
+
+
diff --git a/src/colour.cc b/src/colour.cc
new file mode 100644
index 000000000..92c8d72a6
--- /dev/null
+++ b/src/colour.cc
@@ -0,0 +1,22 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
+ *
+ * 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 as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * 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 "colour.hh"
+
diff --git a/src/colour.hh b/src/colour.hh
new file mode 100644
index 000000000..20a3d4dc3
--- /dev/null
+++ b/src/colour.hh
@@ -0,0 +1,57 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
+ *
+ * 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 as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * 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
+ */
+
+#ifndef PALUDIS_GUARD_SRC_COLOUR_HH
+#define PALUDIS_GUARD_SRC_COLOUR_HH 1
+
+#include <string>
+#include <paludis/stringify.hh>
+#include "src/command_line.hh"
+
+enum Colour
+{
+ cl_red = 31,
+ cl_green = 32,
+ cl_blue = 34,
+
+ cl_bold_red = cl_red + 100,
+ cl_bold_green = cl_green + 100,
+ cl_bold_blue = cl_blue + 100,
+
+ cl_package_name = cl_bold_blue,
+ cl_flag_on = cl_green,
+ cl_flag_off = cl_red,
+ cl_slot = cl_blue,
+ cl_visible = cl_flag_on,
+ cl_masked = cl_flag_off
+};
+
+template <typename T_>
+std::string colour(Colour colour, const T_ & s)
+{
+ if (CommandLine::get_instance()->a_no_color.specified())
+ return paludis::stringify(s);
+ else
+ return "\033[" + paludis::stringify(static_cast<unsigned>(colour) / 100) + ";"
+ + paludis::stringify(static_cast<unsigned>(colour) % 100) + "m" + paludis::stringify(s)
+ + "\033[0;0m";
+}
+
+#endif
diff --git a/src/command_line.cc b/src/command_line.cc
new file mode 100644
index 000000000..9ebe91f32
--- /dev/null
+++ b/src/command_line.cc
@@ -0,0 +1,59 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
+ *
+ * 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 as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * 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 "src/command_line.hh"
+
+#ifndef DOXYGEN
+
+CommandLine::CommandLine() :
+ ArgsHandler(),
+
+ action_args(this, "Actions (specify exactly one)"),
+ a_query(&action_args, "query", 'q', "Query for package information"),
+ a_install(&action_args, "install", 'i', "Install one or more packages"),
+ a_list_repositories(&action_args, "list-repositories", '\0', "List available repositories"),
+ a_version(&action_args, "version", 'V', "Display program version"),
+ a_help(&action_args, "help", 'h', "Display program help"),
+
+ general_args(this, "General options"),
+ a_no_color(&general_args, "no-color", 'c', "Do not use color"),
+ a_no_colour(&a_no_color, "no-colour"),
+
+ query_args(this, "Query options"),
+ a_show_slot(&query_args, "show-slot", 'S', "Show SLOTs"),
+ a_show_license(&query_args, "show-license", 'L', "Show licenses"),
+ a_show_licence(&a_show_license, "show-licence"),
+
+ install_args(this, "Install options"),
+ a_pretend(&install_args, "pretend", 'p', "Pretend only"),
+
+ dl_args(this, "DepList behaviour (use with caution)"),
+ a_dl_rdepend_post(&dl_args, "dl-rdepend-post", '\0', "Treat RDEPEND like PDEPEND where necessary"),
+ a_dl_drop_self_circular(&dl_args, "dl-drop-self-circular", '\0', "Drop self-circular dependencies"),
+ a_dl_drop_circular(&dl_args, "dl-drop-circular", '\0', "Drop circular dependencies"),
+ a_dl_ignore_installed(&dl_args, "dl-ignore-installed", '\0', "Ignore installed packages"),
+ a_dl_recursive_deps(&dl_args, "dl-recursive-deps", '\0', "Check dependencies for installed packages"),
+ a_dl_max_stack_depth(&dl_args, "dl-max-stack-depth", '\0', "Maximum stack depth (default 100)")
+{
+ a_dl_max_stack_depth.set_argument(100);
+}
+
+#endif
+
diff --git a/src/command_line.hh b/src/command_line.hh
new file mode 100644
index 000000000..8ed1a34ce
--- /dev/null
+++ b/src/command_line.hh
@@ -0,0 +1,137 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
+ *
+ * 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 as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * 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
+ */
+
+#ifndef PALUDIS_GUARD_SRC_COMMAND_LINE_HH
+#define PALUDIS_GUARD_SRC_COMMAND_LINE_HH 1
+
+#include <paludis/args/args.hh>
+#include <paludis/instantiation_policy.hh>
+
+/** \file
+ * Declarations for the CommandLine class.
+ */
+
+/**
+ * Our command line.
+ */
+class CommandLine :
+ public paludis::args::ArgsHandler,
+ public paludis::InstantiationPolicy<CommandLine, paludis::instantiation_method::SingletonAsNeededTag>
+{
+ friend class paludis::InstantiationPolicy<CommandLine, paludis::instantiation_method::SingletonAsNeededTag>;
+
+ private:
+ /// Constructor.
+ CommandLine();
+
+ public:
+ /// \name Action arguments
+ ///{
+
+ /// Action arguments.
+ paludis::args::ArgsGroup action_args;
+
+ /// --query
+ paludis::args::SwitchArg a_query;
+
+ /// --install
+ paludis::args::SwitchArg a_install;
+
+ /// --list-repositories
+ paludis::args::SwitchArg a_list_repositories;
+
+ /// --version
+ paludis::args::SwitchArg a_version;
+
+ /// --help
+ paludis::args::SwitchArg a_help;
+
+ ///}
+
+ /// \name General arguments
+ ///{
+
+ /// General arguments.
+ paludis::args::ArgsGroup general_args;
+
+ /// --no-color
+ paludis::args::SwitchArg a_no_color;
+
+ /// --no-colour
+ paludis::args::AliasArg a_no_colour;
+
+ ///}
+
+ /// \name Query arguments
+ ///{
+
+ /// Query arguments.
+ paludis::args::ArgsGroup query_args;
+
+ /// --show-slot
+ paludis::args::SwitchArg a_show_slot;
+
+ /// --show-license
+ paludis::args::SwitchArg a_show_license;
+
+ /// --show-licence
+ paludis::args::AliasArg a_show_licence;
+
+ /// }
+
+ /// \name Install arguments
+ /// {
+
+ /// Install arguments.
+ paludis::args::ArgsGroup install_args;
+
+ /// --pretend
+ paludis::args::SwitchArg a_pretend;
+
+ /// }
+
+ /// \name DepList behaviour arguments
+ /// {
+
+ /// DepList behaviour arguments.
+ paludis::args::ArgsGroup dl_args;
+
+ /// --dl-rdepend-post
+ paludis::args::SwitchArg a_dl_rdepend_post;
+
+ /// --dl-drop-self-circular
+ paludis::args::SwitchArg a_dl_drop_self_circular;
+
+ /// --dl-drop-circular
+ paludis::args::SwitchArg a_dl_drop_circular;
+
+ /// --dl-ignore-installed
+ paludis::args::SwitchArg a_dl_ignore_installed;
+
+ /// --dl-recursive-deps
+ paludis::args::SwitchArg a_dl_recursive_deps;
+
+ /// --dl-max-stack-depth
+ paludis::args::IntegerArg a_dl_max_stack_depth;
+
+ /// }
+};
+
+#endif
diff --git a/src/install.cc b/src/install.cc
new file mode 100644
index 000000000..4b9687b28
--- /dev/null
+++ b/src/install.cc
@@ -0,0 +1,168 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2005, 2006 Ciaran McCreesh <ciaranm@gentoo.org>
+ *
+ * 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 as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * 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 "src/install.hh"
+#include "src/colour.hh"
+#include <paludis/paludis.hh>
+#include <iostream>
+
+/** \file
+ * Handle the --install action for the main paludis program.
+ */
+
+namespace p = paludis;
+
+using std::cerr;
+using std::cout;
+using std::endl;
+
+int
+do_install()
+{
+ int return_code(0);
+
+ p::Context context("When performing install action from command line:");
+ p::Environment * const env(p::DefaultEnvironment::get_instance());
+
+ p::CompositeDepAtom::Pointer targets(new p::AllDepAtom);
+
+ CommandLine::ParametersIterator q(CommandLine::get_instance()->begin_parameters()),
+ q_end(CommandLine::get_instance()->end_parameters());
+ for ( ; q != q_end ; ++q)
+ {
+ /* we might have a dep atom, but we might just have a simple package name
+ * without a category. either should work. also allow full atoms, to make
+ * it easy to test things like '|| ( foo/bar foo/baz )'. */
+ if (std::string::npos != q->find_first_of(" \t\n"))
+ targets->add_child(p::DepParser::parse(*q));
+ else if (std::string::npos == q->find('/'))
+ targets->add_child(p::DepAtom::Pointer(new p::PackageDepAtom(
+ env->package_db()->fetch_unique_qualified_package_name(
+ p::PackageNamePart(*q)))));
+ else
+ targets->add_child(p::DepAtom::Pointer(new p::PackageDepAtom(*q)));
+ }
+
+ p::DepList dep_list(env);
+ dep_list.set_rdepend_post(CommandLine::get_instance()->a_dl_rdepend_post.specified());
+ dep_list.set_drop_self_circular(CommandLine::get_instance()->a_dl_drop_self_circular.specified());
+ dep_list.set_drop_circular(CommandLine::get_instance()->a_dl_drop_circular.specified());
+ dep_list.set_ignore_installed(CommandLine::get_instance()->a_dl_ignore_installed.specified());
+ dep_list.set_recursive_deps(CommandLine::get_instance()->a_dl_recursive_deps.specified());
+ dep_list.set_max_stack_depth(CommandLine::get_instance()->a_dl_max_stack_depth.argument());
+
+ try
+ {
+ dep_list.add(targets);
+
+ for (p::DepList::Iterator dep(dep_list.begin()), dep_end(dep_list.end()) ;
+ dep != dep_end ; ++dep)
+ {
+ /* display name */
+ cout << "* " << colour(cl_package_name, dep->get<p::dle_name>());
+
+ /* display version, unless it's 0 and our category is "virtual" */
+ if ((p::VersionSpec("0") != dep->get<p::dle_version>()) ||
+ p::CategoryNamePart("virtual") != dep->get<p::dle_name>().get<p::qpn_category>())
+ cout << "-" << dep->get<p::dle_version>();
+
+ /* display repository, unless it's our main repository */
+ if (env->package_db()->favourite_repository() != dep->get<p::dle_repository>())
+ cout << "::" << dep->get<p::dle_repository>();
+
+ /* display slot name, unless it's 0 */
+ if (p::SlotName("0") != dep->get<p::dle_slot>())
+ cout << colour(cl_slot, " {:" + stringify(dep->get<p::dle_slot>()) + "}");
+
+ /* fetch metadata */
+ p::PackageDatabaseEntry p(p::PackageDatabaseEntry(dep->get<p::dle_name>(),
+ dep->get<p::dle_version>(), dep->get<p::dle_repository>()));
+ p::VersionMetadata::ConstPointer metadata(env->package_db()->fetch_metadata(p));
+
+ /* display USE flags */
+ for (p::VersionMetadata::IuseIterator i(metadata->begin_iuse()),
+ i_end(metadata->end_iuse()) ; i != i_end ; ++i)
+ {
+ if (env->query_use(*i, &p))
+ cout << " " << colour(cl_flag_on, *i);
+ else if (env->package_db()->fetch_repository(dep->get<p::dle_repository>())->query_use_mask(*i))
+ cout << " " << colour(cl_flag_off, "(-" + p::stringify(*i) + ")");
+ else
+ cout << " " << colour(cl_flag_off, "-" + p::stringify(*i));
+ }
+
+ cout << endl;
+ }
+ }
+ catch (const p::DepListStackTooDeepError & e)
+ {
+ cout << endl;
+ cerr << "DepList stack too deep error:" << endl;
+ cerr << " * " << e.backtrace("\n * ") << e.message() << endl;
+ cerr << endl;
+ cerr << "Try '--dl-max-stack-depth " << std::max(
+ CommandLine::get_instance()->a_dl_max_stack_depth.argument() * 2, 100)
+ << "'." << endl << endl;
+ }
+ catch (const p::DepListError & e)
+ {
+ cout << endl;
+ cerr << "Dependency error:" << endl;
+ cerr << " * " << e.backtrace("\n * ") << e.message() << " ("
+ << e.what() << ")" << endl;
+ cerr << endl;
+
+ dep_list.set_rdepend_post(true);
+ try
+ {
+ dep_list.add(targets);
+ cerr << "Adding --dl-rdepend-post will resolve this." << endl << std::endl;
+ }
+ catch (...)
+ {
+ dep_list.set_drop_self_circular(true);
+ try
+ {
+ dep_list.add(targets);
+ cerr << "Adding --dl-rdepend-post --dl-drop-self-circular "
+ << "will resolve this, but may" << endl
+ << "omit some genuine dependencies." << endl << std::endl;
+ }
+ catch (...)
+ {
+ dep_list.set_drop_circular(true);
+ try
+ {
+ dep_list.add(targets);
+ cerr << "Adding --dl-rdepend-post --dl-drop-circular "
+ << "will resolve this, but may omit" << endl
+ << "some genuine dependencies." << endl << std::endl;
+ }
+ catch (...)
+ {
+ }
+ }
+ }
+
+ return_code |= 1;
+ }
+
+ return return_code;
+}
diff --git a/src/install.hh b/src/install.hh
new file mode 100644
index 000000000..719bf6f3e
--- /dev/null
+++ b/src/install.hh
@@ -0,0 +1,33 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
+ *
+ * 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 as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * 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
+ */
+
+#ifndef PALUDIS_GUARD_SRC_DEPGRAPH_HH
+#define PALUDIS_GUARD_SRC_DEPGRAPH_HH 1
+
+#include "src/command_line.hh"
+
+/** \file
+ * Declaration for the do_install function.
+ */
+
+/// Handle --install.
+int do_install();
+
+#endif
diff --git a/src/list_repositories.cc b/src/list_repositories.cc
new file mode 100644
index 000000000..01201fe6b
--- /dev/null
+++ b/src/list_repositories.cc
@@ -0,0 +1,49 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
+ *
+ * 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 as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * 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 "list_repositories.hh"
+#include "colour.hh"
+#include <paludis/paludis.hh>
+#include <iostream>
+#include <iomanip>
+
+namespace p = paludis;
+
+int do_list_repositories()
+{
+ p::Context context("When performing list-repositories action from command line:");
+ p::Environment * const env(p::DefaultEnvironment::get_instance());
+
+ for (p::IndirectIterator<p::PackageDatabase::RepositoryIterator, const p::Repository>
+ r(env->package_db()->begin_repositories()), r_end(env->package_db()->end_repositories()) ;
+ r != r_end ; ++r)
+ {
+ std::cout << "* " << colour(cl_package_name, r->name()) << std::endl;
+
+ for (p::Repository::InfoIterator i(r->begin_info()), i_end(r->end_info()) ; i != i_end ; ++i)
+ std::cout << " " << std::setw(22) << std::left << (p::stringify(i->first) + ":")
+ << std::setw(0) << " " << i->second << std::endl;
+
+ std::cout << std::endl;
+ }
+
+ return 0;
+}
+
diff --git a/src/list_repositories.hh b/src/list_repositories.hh
new file mode 100644
index 000000000..afa64c77e
--- /dev/null
+++ b/src/list_repositories.hh
@@ -0,0 +1,31 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
+ *
+ * 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 as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * 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
+ */
+
+#ifndef PALUDIS_GUARD_SRC_LIST_REPOSITORIES_HH
+#define PALUDIS_GUARD_SRC_LIST_REPOSITORIES_HH 1
+
+/** \file
+ * Declaration for the do_list_repositories function.
+ */
+
+/// Handle --list-repositories.
+int do_list_repositories();
+
+#endif
diff --git a/src/paludis.cc b/src/paludis.cc
new file mode 100644
index 000000000..660c6596d
--- /dev/null
+++ b/src/paludis.cc
@@ -0,0 +1,160 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2005, 2006 Ciaran McCreesh <ciaranm@gentoo.org>
+ *
+ * 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 <paludis/paludis.hh>
+#include "src/query.hh"
+#include "src/install.hh"
+#include "src/list_repositories.hh"
+#include "src/command_line.hh"
+
+#include <iostream>
+#include <cstdlib>
+
+/** \file
+ * Main paludis program.
+ */
+
+namespace p = paludis;
+
+using std::cout;
+using std::cerr;
+using std::endl;
+
+struct DoHelp
+{
+ const std::string message;
+
+ DoHelp(const std::string & m = "") :
+ message(m)
+ {
+ }
+};
+
+struct DoVersion
+{
+};
+
+int
+main(int argc, char *argv[])
+{
+ p::Context context("In main program:");
+
+ try
+ {
+ context.change_context("When parsing command line arguments:");
+
+ CommandLine::get_instance()->run(argc, argv);
+
+ if (CommandLine::get_instance()->a_help.specified())
+ throw DoHelp();
+
+ if (1 != (CommandLine::get_instance()->a_query.specified() +
+ CommandLine::get_instance()->a_version.specified() +
+ CommandLine::get_instance()->a_install.specified() +
+ CommandLine::get_instance()->a_list_repositories.specified()))
+ throw DoHelp("you should specify exactly one action");
+
+ if (CommandLine::get_instance()->a_version.specified())
+ throw DoVersion();
+
+ if (CommandLine::get_instance()->a_query.specified())
+ {
+ if (CommandLine::get_instance()->empty())
+ throw DoHelp("query action requires at least one parameter");
+
+ return do_query();
+ }
+
+ if (CommandLine::get_instance()->a_install.specified())
+ {
+ if (CommandLine::get_instance()->empty())
+ throw DoHelp("install action requires at least one parameter");
+
+ return do_install();
+ }
+
+ if (CommandLine::get_instance()->a_list_repositories.specified())
+ {
+ if (! CommandLine::get_instance()->empty())
+ throw DoHelp("list-repositories action takes no parameters");
+
+ return do_list_repositories();
+ }
+
+ throw p::InternalError(__PRETTY_FUNCTION__, "no action?");
+ }
+ catch (const DoVersion &)
+ {
+ cout << PALUDIS_PACKAGE << " " << PALUDIS_VERSION_MAJOR << "."
+ << PALUDIS_VERSION_MINOR << "." << PALUDIS_VERSION_MICRO;
+ if (! std::string(PALUDIS_SUBVERSION_REVISION).empty())
+ cout << " svn " << PALUDIS_SUBVERSION_REVISION;
+ cout << endl << endl;
+ cout << "Built by " << PALUDIS_BUILD_USER << "@" << PALUDIS_BUILD_HOST
+ << " on " << PALUDIS_BUILD_DATE << endl;
+ cout << "Compiler: " << PALUDIS_BUILD_CXX << endl;
+ cout << "CXXFLAGS: " << PALUDIS_BUILD_CXXFLAGS << endl;
+ cout << "LDFLAGS: " << PALUDIS_BUILD_LDFLAGS << endl;
+ cout << "SYSCONFDIR: " << SYSCONFDIR << endl;
+ cout << endl;
+ cout << "Paludis comes with ABSOLUTELY NO WARRANTY. Paludis is free software, and you" << endl;
+ cout << "are welcome to redistribute it under the terms of the GNU General Public" << endl;
+ cout << "License, version 2." << endl;
+
+ return EXIT_SUCCESS;
+ }
+ catch (const DoHelp & h)
+ {
+ if (h.message.empty())
+ {
+ cout << "Usage: " << argv[0] << " [options]" << endl;
+ cout << endl;
+ cout << *CommandLine::get_instance();
+ }
+ else
+ {
+ cerr << "Usage error: " << h.message << endl;
+ cerr << "Try " << argv[0] << " --help" << endl;
+ }
+ return EXIT_FAILURE;
+ }
+ catch (const p::Exception & e)
+ {
+ cout << endl;
+ cerr << "Unhandled exception:" << endl
+ << " * " << e.backtrace("\n * ")
+ << e.message() << " (" << e.what() << ")" << endl;
+ return EXIT_FAILURE;
+ }
+ catch (const std::exception & e)
+ {
+ cout << endl;
+ cerr << "Unhandled exception:" << endl
+ << " * " << e.what() << endl;
+ return EXIT_FAILURE;
+ }
+ catch (...)
+ {
+ cout << endl;
+ cerr << "Unhandled exception:" << endl
+ << " * Unknown exception type. Ouch..." << endl;
+ return EXIT_FAILURE;
+ }
+}
+
diff --git a/src/query.cc b/src/query.cc
new file mode 100644
index 000000000..7c70e16a8
--- /dev/null
+++ b/src/query.cc
@@ -0,0 +1,169 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
+ *
+ * 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 as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * 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 "src/query.hh"
+#include "src/colour.hh"
+#include <paludis/paludis.hh>
+#include <iostream>
+#include <iomanip>
+#include <string>
+#include <functional>
+
+/** \file
+ * Handle the --query action for the main paludis program.
+ */
+
+namespace p = paludis;
+
+void do_one_query(
+ const p::Environment * const env,
+ const std::string & q)
+{
+ p::Context local_context("When handling query '" + q + "':");
+
+ /* we might have a dep atom, but we might just have a simple package name
+ * without a category. either should work. */
+ p::PackageDepAtom::Pointer atom(std::string::npos == q.find('/') ?
+ new p::PackageDepAtom(env->package_db()->fetch_unique_qualified_package_name(
+ p::PackageNamePart(q))) :
+ new p::PackageDepAtom(q));
+
+ p::PackageDatabaseEntryCollection::ConstPointer entries(env->package_db()->query(atom));
+ if (entries->empty())
+ throw p::NoSuchPackageError(q);
+
+ /* match! display it. */
+ std::cout << "* " << colour(cl_package_name, entries->begin()->get<p::pde_package>());
+ if (atom->version_spec_ptr())
+ std::cout << " (" << atom->version_operator() << *atom->version_spec_ptr() << ")";
+ std::cout << std::endl;
+
+ /* find all repository names. */
+ p::RepositoryNameCollection repo_names;
+ p::PackageDatabaseEntryCollection::Iterator e(entries->begin()), e_end(entries->end());
+ for ( ; e != e_end ; ++e)
+ repo_names.append(e->get<p::pde_repository>());
+
+ /* display versions, by repository. */
+ p::RepositoryNameCollection::Iterator r(repo_names.begin()), r_end(repo_names.end());
+ for ( ; r != r_end ; ++r)
+ {
+ std::cout << " " << std::setw(22) << std::left <<
+ (p::stringify(*r) + ":") << std::setw(0) << " ";
+
+ std::string old_slot;
+ for (e = entries->begin() ; e != e_end ; ++e)
+ if (e->get<p::pde_repository>() == *r)
+ {
+ p::VersionMetadata::ConstPointer metadata(env->package_db()->fetch_metadata(*e));
+ if (CommandLine::get_instance()->a_show_slot.specified())
+ {
+ /* show the slot, if we're about to move onto a new slot */
+ std::string slot_name(metadata->get(p::vmk_slot));
+ if (old_slot.empty())
+ old_slot = slot_name;
+ else if (old_slot != slot_name)
+ std::cout << colour(cl_slot, "{:" + old_slot + "} ");
+ old_slot = slot_name;
+ }
+
+ const p::MaskReasons masks(env->mask_reasons(*e));
+
+ if (masks.none())
+ std::cout << colour(cl_visible, e->get<p::pde_version>());
+ else
+ {
+ std::string reasons;
+ if (masks.test(p::mr_keyword))
+ reasons.append("K");
+ if (masks.test(p::mr_user_mask))
+ reasons.append("U");
+ if (masks.test(p::mr_profile_mask))
+ reasons.append("P");
+ if (masks.test(p::mr_repository_mask))
+ reasons.append("R");
+ if (masks.test(p::mr_eapi))
+ reasons.append("E");
+ std::cout << colour(cl_masked, "(" + stringify(e->get<p::pde_version>()) + ")" + reasons);
+ }
+ /// \todo ^^ text description of masks
+
+ if (e == entries->last())
+ std::cout << "*";
+ std::cout << " ";
+ }
+
+ /* still need to show the slot for the last item */
+ if (CommandLine::get_instance()->a_show_slot.specified())
+ std::cout << colour(cl_slot, "{:" + old_slot + "} ");
+
+ std::cout << std::endl;
+ }
+
+ /* display metadata */
+ p::VersionMetadata::ConstPointer metadata(env->package_db()->fetch_metadata(*entries->last()));
+ std::cout << " " << std::setw(22) << std::left << "Homepage:" << std::setw(0) <<
+ " " << metadata->get(p::vmk_homepage) << std::endl;
+ std::cout << " " << std::setw(22) << std::left << "Description:" << std::setw(0) <<
+ " " << metadata->get(p::vmk_description) << std::endl;
+ if (CommandLine::get_instance()->a_show_license.specified())
+ std::cout << " " << std::setw(22) << std::left << "License:" << std::setw(0) <<
+ " " << metadata->get(p::vmk_license) << std::endl;
+
+ /* blank line */
+ std::cout << std::endl;
+}
+
+int do_query()
+{
+ int return_code(0);
+
+ p::Context context("When performing query action from command line:");
+ p::Environment * const env(p::DefaultEnvironment::get_instance());
+
+ CommandLine::ParametersIterator q(CommandLine::get_instance()->begin_parameters()),
+ q_end(CommandLine::get_instance()->end_parameters());
+ for ( ; q != q_end ; ++q)
+ {
+ try
+ {
+ do_one_query(env, *q);
+ }
+ catch (const p::NameError & e)
+ {
+ return_code |= 1;
+ std::cout << std::endl;
+ std::cerr << "Query error:" << std::endl;
+ std::cerr << " * " << e.backtrace("\n * ") << e.message() << std::endl;
+ std::cerr << std::endl;
+ }
+ catch (const p::PackageDatabaseLookupError & e)
+ {
+ return_code |= 1;
+ std::cout << std::endl;
+ std::cerr << "Query error:" << std::endl;
+ std::cerr << " * " << e.backtrace("\n * ") << e.message() << std::endl;
+ std::cerr << std::endl;
+ }
+ }
+
+ return return_code;
+}
+
diff --git a/src/query.hh b/src/query.hh
new file mode 100644
index 000000000..e74760757
--- /dev/null
+++ b/src/query.hh
@@ -0,0 +1,33 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaranm@gentoo.org>
+ *
+ * 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 as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * 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
+ */
+
+#ifndef PALUDIS_GUARD_SRC_QUERY_HH
+#define PALUDIS_GUARD_SRC_QUERY_HH 1
+
+#include "src/command_line.hh"
+
+/** \file
+ * Declaration for the do_query function.
+ */
+
+/// Handle --query.
+int do_query();
+
+#endif