aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Saleem Abdulrasool <compnerd@compnerd.org> 2008-11-16 20:43:14 -0800
committerAvatar David Leverton <levertond@googlemail.com> 2008-11-17 21:53:24 +0000
commitb3c0daf8d515b414c7089908ea26ce842be01560 (patch)
treec880631b1b8662e2386d6e9386c2aee18e4d7e1f
parent15f1ce1eef979e22d35241a2c0d266d5bda4e754 (diff)
downloadpaludis-b3c0daf8d515b414c7089908ea26ce842be01560.tar.gz
paludis-b3c0daf8d515b414c7089908ea26ce842be01560.tar.xz
add --help option to commands
add a CaveCommandCommandLine base class. This class contains a --help option for cave commands.
-rw-r--r--src/clients/cave/Makefile.am1
-rw-r--r--src/clients/cave/cmd_help.cc3
-rw-r--r--src/clients/cave/cmd_print_categories.cc10
-rw-r--r--src/clients/cave/cmd_print_commands.cc10
-rw-r--r--src/clients/cave/cmd_print_environment_metadata.cc10
-rw-r--r--src/clients/cave/cmd_print_id_contents.cc10
-rw-r--r--src/clients/cave/cmd_print_id_metadata.cc10
-rw-r--r--src/clients/cave/cmd_print_ids.cc10
-rw-r--r--src/clients/cave/cmd_print_repositories.cc10
-rw-r--r--src/clients/cave/cmd_print_sets.cc10
-rw-r--r--src/clients/cave/cmd_print_sync_protocols.cc10
-rw-r--r--src/clients/cave/cmd_show.cc10
-rw-r--r--src/clients/cave/cmd_sync.cc10
-rw-r--r--src/clients/cave/command.hh2
-rw-r--r--src/clients/cave/command_command_line.cc43
-rw-r--r--src/clients/cave/command_command_line.hh47
16 files changed, 193 insertions, 13 deletions
diff --git a/src/clients/cave/Makefile.am b/src/clients/cave/Makefile.am
index 8323429..7143e1c 100644
--- a/src/clients/cave/Makefile.am
+++ b/src/clients/cave/Makefile.am
@@ -66,6 +66,7 @@ libcave_a_SOURCES = \
colour_formatter.cc colour_formatter.hh \
command.cc command.hh \
command_line.cc command_line.hh \
+ command_command_line.cc command_command_line.hh \
command_factory.cc command_factory.hh \
cmd_help.cc cmd_help.hh \
cmd_print_categories.cc cmd_print_categories.hh \
diff --git a/src/clients/cave/cmd_help.cc b/src/clients/cave/cmd_help.cc
index c9a4ff7..7c89946 100644
--- a/src/clients/cave/cmd_help.cc
+++ b/src/clients/cave/cmd_help.cc
@@ -28,6 +28,7 @@
#include <paludis/util/make_shared_ptr.hh>
#include "command_factory.hh"
+#include "command_command_line.hh"
using namespace paludis;
using namespace cave;
@@ -37,7 +38,7 @@ using std::cout;
namespace
{
struct HelpCommandLine :
- args::ArgsHandler
+ CaveCommandCommandLine
{
args::ArgsGroup g_general;
args::SwitchArg a_all;
diff --git a/src/clients/cave/cmd_print_categories.cc b/src/clients/cave/cmd_print_categories.cc
index e69a0e3..a66c5c7 100644
--- a/src/clients/cave/cmd_print_categories.cc
+++ b/src/clients/cave/cmd_print_categories.cc
@@ -32,6 +32,8 @@
#include <algorithm>
#include <set>
+#include "command_command_line.hh"
+
using namespace paludis;
using namespace cave;
using std::cout;
@@ -40,7 +42,7 @@ using std::endl;
namespace
{
struct PrintCategoriesCommandLine :
- args::ArgsHandler
+ CaveCommandCommandLine
{
virtual std::string app_name() const
{
@@ -86,6 +88,12 @@ PrintCategoriesCommand::run(
PrintCategoriesCommandLine cmdline;
cmdline.run(args, "CAVE", "CAVE_PRINT_CATEGORIES_OPTIONS", "CAVE_PRINT_CATEGORIES_CMDLINE");
+ if (cmdline.a_help.specified())
+ {
+ cout << cmdline;
+ return EXIT_SUCCESS;
+ }
+
if (cmdline.begin_parameters() != cmdline.end_parameters())
throw args::DoHelp("print-categories takes no parameters");
diff --git a/src/clients/cave/cmd_print_commands.cc b/src/clients/cave/cmd_print_commands.cc
index 35262e4..9c25b90 100644
--- a/src/clients/cave/cmd_print_commands.cc
+++ b/src/clients/cave/cmd_print_commands.cc
@@ -27,6 +27,8 @@
#include <algorithm>
#include <set>
+#include "command_command_line.hh"
+
using namespace paludis;
using namespace cave;
using std::cout;
@@ -35,7 +37,7 @@ using std::endl;
namespace
{
struct PrintCommandsCommandLine :
- args::ArgsHandler
+ CaveCommandCommandLine
{
virtual std::string app_name() const
{
@@ -69,6 +71,12 @@ PrintCommandsCommand::run(
PrintCommandsCommandLine cmdline;
cmdline.run(args, "CAVE", "CAVE_PRINT_COMMANDS_OPTIONS", "CAVE_PRINT_COMMANDS_CMDLINE");
+ if (cmdline.a_help.specified())
+ {
+ cout << cmdline;
+ return EXIT_SUCCESS;
+ }
+
if (cmdline.begin_parameters() != cmdline.end_parameters())
throw args::DoHelp("print-commands takes no parameters");
diff --git a/src/clients/cave/cmd_print_environment_metadata.cc b/src/clients/cave/cmd_print_environment_metadata.cc
index bc7740c..0b4ec9b 100644
--- a/src/clients/cave/cmd_print_environment_metadata.cc
+++ b/src/clients/cave/cmd_print_environment_metadata.cc
@@ -31,6 +31,8 @@
#include <iostream>
#include <algorithm>
+#include "command_command_line.hh"
+
using namespace paludis;
using namespace cave;
using std::cout;
@@ -39,7 +41,7 @@ using std::endl;
namespace
{
struct PrintEnvironmentMetadataCommandLine :
- args::ArgsHandler
+ CaveCommandCommandLine
{
virtual std::string app_name() const
{
@@ -120,6 +122,12 @@ PrintEnvironmentMetadataCommand::run(
PrintEnvironmentMetadataCommandLine cmdline;
cmdline.run(args, "CAVE", "CAVE_PRINT_ENVIRONMENT_METADATA_OPTIONS", "CAVE_PRINT_ENVIRONMENT_METADATA_CMDLINE");
+ if (cmdline.a_help.specified())
+ {
+ cout << cmdline;
+ return EXIT_SUCCESS;
+ }
+
if (cmdline.begin_parameters() != cmdline.end_parameters())
throw args::DoHelp("print-environment-metadata takes no parameters");
diff --git a/src/clients/cave/cmd_print_id_contents.cc b/src/clients/cave/cmd_print_id_contents.cc
index 4b36488..9ed2bb8 100644
--- a/src/clients/cave/cmd_print_id_contents.cc
+++ b/src/clients/cave/cmd_print_id_contents.cc
@@ -41,6 +41,8 @@
#include <algorithm>
#include <set>
+#include "command_command_line.hh"
+
using namespace paludis;
using namespace cave;
using std::cout;
@@ -49,7 +51,7 @@ using std::endl;
namespace
{
struct PrintContentsCommandLine :
- args::ArgsHandler
+ CaveCommandCommandLine
{
virtual std::string app_name() const
{
@@ -98,6 +100,12 @@ PrintIDContentsCommand::run(
PrintContentsCommandLine cmdline;
cmdline.run(args, "CAVE", "CAVE_PRINT_ID_CONTENTS_OPTIONS", "CAVE_PRINT_ID_CONTENTS_CMDLINE");
+ if (cmdline.a_help.specified())
+ {
+ cout << cmdline;
+ return EXIT_SUCCESS;
+ }
+
if (1 != std::distance(cmdline.begin_parameters(), cmdline.end_parameters()))
throw args::DoHelp("print-id-contents takes exactly one parameter");
diff --git a/src/clients/cave/cmd_print_id_metadata.cc b/src/clients/cave/cmd_print_id_metadata.cc
index b8c6633..e9aed60 100644
--- a/src/clients/cave/cmd_print_id_metadata.cc
+++ b/src/clients/cave/cmd_print_id_metadata.cc
@@ -39,6 +39,8 @@
#include <iostream>
#include <algorithm>
+#include "command_command_line.hh"
+
using namespace paludis;
using namespace cave;
using std::cout;
@@ -47,7 +49,7 @@ using std::endl;
namespace
{
struct PrintIDMetadataCommandLine :
- args::ArgsHandler
+ CaveCommandCommandLine
{
virtual std::string app_name() const
{
@@ -133,6 +135,12 @@ PrintIDMetadataCommand::run(
PrintIDMetadataCommandLine cmdline;
cmdline.run(args, "CAVE", "CAVE_PRINT_ID_METADATA_OPTIONS", "CAVE_PRINT_ID_METADATA_CMDLINE");
+ if (cmdline.a_help.specified())
+ {
+ cout << cmdline;
+ return EXIT_SUCCESS;
+ }
+
if (1 != std::distance(cmdline.begin_parameters(), cmdline.end_parameters()))
throw args::DoHelp("print-id-metadata takes exactly one parameter");
diff --git a/src/clients/cave/cmd_print_ids.cc b/src/clients/cave/cmd_print_ids.cc
index 534a251..6c3d23a 100644
--- a/src/clients/cave/cmd_print_ids.cc
+++ b/src/clients/cave/cmd_print_ids.cc
@@ -42,6 +42,8 @@
#include <iostream>
#include <algorithm>
+#include "command_command_line.hh"
+
using namespace paludis;
using namespace cave;
using std::cout;
@@ -50,7 +52,7 @@ using std::endl;
namespace
{
struct PrintIDsCommandLine :
- args::ArgsHandler
+ CaveCommandCommandLine
{
virtual std::string app_name() const
{
@@ -242,6 +244,12 @@ PrintIDsCommand::run(
PrintIDsCommandLine cmdline;
cmdline.run(args, "CAVE", "CAVE_PRINT_IDS_OPTIONS", "CAVE_PRINT_IDS_CMDLINE");
+ if (cmdline.a_help.specified())
+ {
+ cout << cmdline;
+ return EXIT_SUCCESS;
+ }
+
if (cmdline.begin_parameters() != cmdline.end_parameters())
throw args::DoHelp("print-ids takes no parameters");
diff --git a/src/clients/cave/cmd_print_repositories.cc b/src/clients/cave/cmd_print_repositories.cc
index 9d2abf5..92b90bb 100644
--- a/src/clients/cave/cmd_print_repositories.cc
+++ b/src/clients/cave/cmd_print_repositories.cc
@@ -35,6 +35,8 @@
#include <algorithm>
#include <cstdlib>
+#include "command_command_line.hh"
+
using namespace paludis;
using namespace cave;
using std::cout;
@@ -43,7 +45,7 @@ using std::endl;
namespace
{
struct PrintRepositoriesCommandLine :
- args::ArgsHandler
+ CaveCommandCommandLine
{
virtual std::string app_name() const
{
@@ -82,6 +84,12 @@ PrintRepositoriesCommand::run(
PrintRepositoriesCommandLine cmdline;
cmdline.run(args, "CAVE", "CAVE_PRINT_REPOSITORIES_OPTIONS", "CAVE_PRINT_REPOSITORIES_CMDLINE");
+ if (cmdline.a_help.specified())
+ {
+ cout << cmdline;
+ return EXIT_SUCCESS;
+ }
+
if (cmdline.begin_parameters() != cmdline.end_parameters())
throw args::DoHelp("print-repositories takes no parameters");
diff --git a/src/clients/cave/cmd_print_sets.cc b/src/clients/cave/cmd_print_sets.cc
index 9b50903..98479f2 100644
--- a/src/clients/cave/cmd_print_sets.cc
+++ b/src/clients/cave/cmd_print_sets.cc
@@ -33,6 +33,8 @@
#include <iostream>
#include <set>
+#include "command_command_line.hh"
+
using namespace paludis;
using namespace cave;
using std::cout;
@@ -41,7 +43,7 @@ using std::endl;
namespace
{
struct PrintSetsCommandLine :
- args::ArgsHandler
+ CaveCommandCommandLine
{
virtual std::string app_name() const
{
@@ -70,6 +72,12 @@ PrintSetsCommand::run(
PrintSetsCommandLine cmdline;
cmdline.run(args, "CAVE", "CAVE_PRINT_SETS_OPTIONS", "CAVE_PRINT_SETS_CMDLINE");
+ if (cmdline.a_help.specified())
+ {
+ cout << cmdline;
+ return EXIT_SUCCESS;
+ }
+
if (cmdline.begin_parameters() != cmdline.end_parameters())
throw args::DoHelp("print-sets takes no parameters");
diff --git a/src/clients/cave/cmd_print_sync_protocols.cc b/src/clients/cave/cmd_print_sync_protocols.cc
index 230ff4e..1d97ada 100644
--- a/src/clients/cave/cmd_print_sync_protocols.cc
+++ b/src/clients/cave/cmd_print_sync_protocols.cc
@@ -32,6 +32,8 @@
#include <iostream>
#include <set>
+#include "command_command_line.hh"
+
using namespace paludis;
using namespace cave;
using std::cout;
@@ -40,7 +42,7 @@ using std::endl;
namespace
{
struct PrintSyncProtocolsCommandLine :
- args::ArgsHandler
+ CaveCommandCommandLine
{
virtual std::string app_name() const
{
@@ -69,6 +71,12 @@ PrintSyncProtocolsCommand::run(
PrintSyncProtocolsCommandLine cmdline;
cmdline.run(args, "CAVE", "CAVE_PRINT_SYNC_PROTOCOLS_OPTIONS", "CAVE_PRINT_SYNC_PROTOCOLS_CMDLINE");
+ if (cmdline.a_help.specified())
+ {
+ cout << cmdline;
+ return EXIT_SUCCESS;
+ }
+
if (cmdline.begin_parameters() != cmdline.end_parameters())
throw args::DoHelp("print-sync-protocols takes no parameters");
diff --git a/src/clients/cave/cmd_show.cc b/src/clients/cave/cmd_show.cc
index 8e27cf9..9509126 100644
--- a/src/clients/cave/cmd_show.cc
+++ b/src/clients/cave/cmd_show.cc
@@ -49,6 +49,8 @@
#include <algorithm>
#include <set>
+#include "command_command_line.hh"
+
using namespace paludis;
using namespace cave;
using std::cout;
@@ -57,7 +59,7 @@ using std::endl;
namespace
{
struct ShowCommandLine :
- args::ArgsHandler
+ CaveCommandCommandLine
{
virtual std::string app_name() const
{
@@ -678,6 +680,12 @@ ShowCommand::run(
ShowCommandLine cmdline;
cmdline.run(args, "CAVE", "CAVE_SHOW_OPTIONS", "CAVE_SHOW_CMDLINE");
+ if (cmdline.a_help.specified())
+ {
+ cout << cmdline;
+ return EXIT_SUCCESS;
+ }
+
if (cmdline.begin_parameters() == cmdline.end_parameters())
throw args::DoHelp("show requires at least one parameter");
diff --git a/src/clients/cave/cmd_sync.cc b/src/clients/cave/cmd_sync.cc
index e71b7cf..f876d70 100644
--- a/src/clients/cave/cmd_sync.cc
+++ b/src/clients/cave/cmd_sync.cc
@@ -39,6 +39,8 @@
#include <map>
#include <set>
+#include "command_command_line.hh"
+
using namespace paludis;
using namespace cave;
using std::cout;
@@ -57,7 +59,7 @@ namespace paludis
namespace
{
struct SyncCommandLine :
- args::ArgsHandler
+ CaveCommandCommandLine
{
virtual std::string app_name() const
{
@@ -270,6 +272,12 @@ SyncCommand::run(
SyncCommandLine cmdline;
cmdline.run(args, "CAVE", "CAVE_SYNC_OPTIONS", "CAVE_SYNC_CMDLINE");
+ if (cmdline.a_help.specified())
+ {
+ cout << cmdline;
+ return EXIT_SUCCESS;
+ }
+
int retcode(0);
Messages messages;
diff --git a/src/clients/cave/command.hh b/src/clients/cave/command.hh
index 14f646b..e235ac8 100644
--- a/src/clients/cave/command.hh
+++ b/src/clients/cave/command.hh
@@ -34,7 +34,7 @@ namespace paludis
public:
virtual ~Command() = 0;
- virtual bool important() const;
+ virtual bool important() const PALUDIS_ATTRIBUTE((warn_unused_result));
virtual int run(
const std::tr1::shared_ptr<Environment> &,
diff --git a/src/clients/cave/command_command_line.cc b/src/clients/cave/command_command_line.cc
new file mode 100644
index 0000000..7f5af7d
--- /dev/null
+++ b/src/clients/cave/command_command_line.cc
@@ -0,0 +1,43 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 Saleem Abdulrasool
+ *
+ * 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_command_line.hh"
+
+using namespace paludis;
+using namespace cave;
+
+CaveCommandCommandLine::CaveCommandCommandLine() :
+ g_global_options(this, "Global Options", "Global options, used by every subcommand."),
+ a_help(&g_global_options, "help", 'h', "display help message")
+{
+}
+
+std::ostream &
+paludis::cave::operator<< (std::ostream & os, const CaveCommandCommandLine & cmdline)
+{
+ os << "usage: " << cmdline.app_name() << " ";
+ std::copy(cmdline.begin_usage_lines(), cmdline.end_usage_lines(),
+ std::ostream_iterator<std::string>(os, "\n"));
+ os << std::endl;
+
+ os << static_cast<const args::ArgsHandler &>(cmdline);
+
+ return os;
+}
+
diff --git a/src/clients/cave/command_command_line.hh b/src/clients/cave/command_command_line.hh
new file mode 100644
index 0000000..2174b7a
--- /dev/null
+++ b/src/clients/cave/command_command_line.hh
@@ -0,0 +1,47 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 Saleem Abdulrasool
+ *
+ * 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
+ */
+
+#ifndef PALUDIS_GUARD_SRC_CLIENTS_CAVE_COMMAND_COMMAND_LINE_HH
+#define PALUDIS_GUARD_SRC_CLIENTS_CAVE_COMMAND_COMMAND_LINE_HH 1
+
+#include <iosfwd>
+#include <paludis/args/args.hh>
+
+namespace paludis
+{
+ namespace cave
+ {
+ struct CaveCommandCommandLine :
+ args::ArgsHandler
+ {
+ friend std::ostream & operator<< (std::ostream &, const CaveCommandCommandLine &);
+
+ args::ArgsGroup g_global_options;
+ args::SwitchArg a_help;
+
+ CaveCommandCommandLine();
+ };
+
+ std::ostream &
+ operator<< (std::ostream &, const CaveCommandCommandLine &) PALUDIS_VISIBLE;
+ }
+}
+
+#endif
+