aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-04 11:30:23 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2010-07-04 12:10:17 +0100
commiteefb8e91a53962e4b570ca4f792ec59c7a1b4f2e (patch)
treedd06a3edf7e8174845e99ef11de64246af2c2b95
parent15adad88e818f0149a892a137d21c73d5613bd18 (diff)
downloadpaludis-eefb8e91a53962e4b570ca4f792ec59c7a1b4f2e.tar.gz
paludis-eefb8e91a53962e4b570ca4f792ec59c7a1b4f2e.tar.xz
cave --help / --version
Fixes: ticket:908
-rw-r--r--src/clients/cave/cave.cc33
-rw-r--r--src/clients/cave/command_command_line.cc16
-rw-r--r--src/clients/cave/command_line.cc4
-rw-r--r--src/clients/cave/command_line.hh4
4 files changed, 50 insertions, 7 deletions
diff --git a/src/clients/cave/cave.cc b/src/clients/cave/cave.cc
index 63a1b9a..d5abf23 100644
--- a/src/clients/cave/cave.cc
+++ b/src/clients/cave/cave.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2008, 2009 Ciaran McCreesh
+ * Copyright (c) 2008, 2009, 2010 Ciaran McCreesh
*
* 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
@@ -25,9 +25,11 @@
#include <paludis/environment_factory.hh>
#include <paludis/environment.hh>
#include <paludis/action.hh>
+#include <paludis/about.hh>
#include <iostream>
#include <cstdlib>
#include <string>
+#include <algorithm>
#include "command_factory.hh"
#include "command_line.hh"
@@ -46,6 +48,35 @@ int main(int argc, char * argv[])
cave::CaveCommandLine cmdline;
cmdline.run(argc, argv, "CAVE", "CAVE_OPTIONS", "CAVE_CMDLINE", args::ArgsHandlerOptions() + args::aho_stop_on_first_parameter);
+ if (cmdline.a_help.specified())
+ {
+ if (cmdline.begin_usage_lines() != cmdline.end_usage_lines())
+ {
+ cout << "usage: ";
+ for (args::ArgsHandler::UsageLineConstIterator u_begin(cmdline.begin_usage_lines()), u(u_begin), u_end(cmdline.end_usage_lines()) ;
+ u != u_end ; ++u)
+ {
+ if (u != u_begin)
+ cout << " ";
+ cout << cmdline.app_name() << " " << *u << endl;
+ }
+ }
+ cout << endl;
+ cout << cmdline;
+ cout << "See 'cave help [ --all ]' or 'man cave' for command names and options for those" << endl;
+ cout << "commands" << endl;
+ return EXIT_SUCCESS;
+ }
+ else if (cmdline.a_version.specified())
+ {
+ cout << PALUDIS_PACKAGE << " " << PALUDIS_VERSION_MAJOR << "."
+ << PALUDIS_VERSION_MINOR << "." << PALUDIS_VERSION_MICRO << PALUDIS_VERSION_SUFFIX;
+ if (! std::string(PALUDIS_GIT_HEAD).empty())
+ cout << " git " << PALUDIS_GIT_HEAD;
+ cout << endl;
+ return EXIT_SUCCESS;
+ }
+
if (cmdline.begin_parameters() == cmdline.end_parameters())
throw args::DoHelp();
diff --git a/src/clients/cave/command_command_line.cc b/src/clients/cave/command_command_line.cc
index 4a6b698..b7e7be0 100644
--- a/src/clients/cave/command_command_line.cc
+++ b/src/clients/cave/command_command_line.cc
@@ -31,10 +31,18 @@ CaveCommandCommandLine::CaveCommandCommandLine() :
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;
+ if (cmdline.begin_usage_lines() != cmdline.end_usage_lines())
+ {
+ os << "usage: ";
+ for (args::ArgsHandler::UsageLineConstIterator u_begin(cmdline.begin_usage_lines()), u(u_begin), u_end(cmdline.end_usage_lines()) ;
+ u != u_end ; ++u)
+ {
+ if (u != u_begin)
+ os << " ";
+ os << cmdline.app_name() << " " << *u << std::endl;
+ }
+ os << std::endl;
+ }
os << static_cast<const args::ArgsHandler &>(cmdline);
diff --git a/src/clients/cave/command_line.cc b/src/clients/cave/command_line.cc
index 14e9c58..8b2f963 100644
--- a/src/clients/cave/command_line.cc
+++ b/src/clients/cave/command_line.cc
@@ -26,7 +26,9 @@ CaveCommandLine::CaveCommandLine() :
g_global_options(main_options_section(), "Global Options", "Global options, used by every subcommand."),
a_environment(&g_global_options, "environment", 'E',
"Environment specification (class:suffix, both parts optional)"),
- a_log_level(&g_global_options, "log-level", '\0')
+ a_log_level(&g_global_options, "log-level", '\0'),
+ a_help(&g_global_options, "help", 'h', "display help message", false),
+ a_version(&g_global_options, "version", 'v', "display version information", false)
{
add_usage_line("[ --environment class:suffix ] [ --log-level level ] COMMAND [ARGS...]");
diff --git a/src/clients/cave/command_line.hh b/src/clients/cave/command_line.hh
index 7e000c1..1869afb 100644
--- a/src/clients/cave/command_line.hh
+++ b/src/clients/cave/command_line.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2008 Ciaran McCreesh
+ * Copyright (c) 2008, 2010 Ciaran McCreesh
*
* 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
@@ -48,6 +48,8 @@ namespace paludis
args::ArgsGroup g_global_options;
args::StringArg a_environment;
args::LogLevelArg a_log_level;
+ args::SwitchArg a_help;
+ args::SwitchArg a_version;
CaveCommandLine();
};