aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Mike Kelly <pioto@pioto.org> 2009-09-09 00:54:10 -0400
committerAvatar Mike Kelly <pioto@pioto.org> 2009-09-09 15:00:07 -0400
commit4d63e7b76e97c6afbd3c92564cfba6590bb0562c (patch)
tree7c9d94ba0c77c870faa93016e9a432c379a1424b
parentf4786f3c551b4a330286d80a128bffa8e48a3841 (diff)
downloadpaludis-4d63e7b76e97c6afbd3c92564cfba6590bb0562c.tar.gz
paludis-4d63e7b76e97c6afbd3c92564cfba6590bb0562c.tar.xz
Add cave-print-commands --all.
Default to only printing the important commands by default, add -a to get the old behavior.
-rw-r--r--src/clients/cave/cmd_print_commands.cc22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/clients/cave/cmd_print_commands.cc b/src/clients/cave/cmd_print_commands.cc
index 9c25b90..af3d202 100644
--- a/src/clients/cave/cmd_print_commands.cc
+++ b/src/clients/cave/cmd_print_commands.cc
@@ -20,6 +20,7 @@
#include "cmd_print_commands.hh"
#include "command_factory.hh"
#include <paludis/util/make_shared_ptr.hh>
+#include <paludis/util/stringify.hh>
#include <paludis/args/args.hh>
#include <paludis/args/do_help.hh>
#include <cstdlib>
@@ -55,9 +56,14 @@ namespace
"parsing by scripts.";
}
- PrintCommandsCommandLine()
+ args::ArgsGroup g_general;
+ args::SwitchArg a_all;
+
+ PrintCommandsCommandLine() :
+ g_general(main_options_section(), "General Options", "General Options"),
+ a_all(&g_general, "all", 'a', "Print all available commands.", false)
{
- add_usage_line("");
+ add_usage_line("[-a|--all]");
}
};
}
@@ -80,8 +86,16 @@ PrintCommandsCommand::run(
if (cmdline.begin_parameters() != cmdline.end_parameters())
throw args::DoHelp("print-commands takes no parameters");
- std::copy(CommandFactory::get_instance()->begin(), CommandFactory::get_instance()->end(),
- std::ostream_iterator<std::string>(cout, "\n"));
+ for (CommandFactory::ConstIterator cmd(CommandFactory::get_instance()->begin()), cmd_end(CommandFactory::get_instance()->end()) ;
+ cmd != cmd_end ; ++cmd)
+ {
+ std::tr1::shared_ptr<Command> instance(CommandFactory::get_instance()->create(*cmd));
+
+ if (! cmdline.a_all.specified() && ! instance->important())
+ continue;
+
+ cout << stringify(*cmd) << endl;
+ }
return EXIT_SUCCESS;
}