aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Alex Elsayed <eternaleye@gmail.com> 2011-06-28 13:03:21 -0700
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-06-30 10:27:28 +0100
commit0b3117db9a5baed87bf08ce571777e1a401c1814 (patch)
tree23bbf448187bf5e98bdab8b80b45005c2983b64f
parentb6f5d29a9561fd16a28b57850a10c605cd9d5c90 (diff)
downloadpaludis-0b3117db9a5baed87bf08ce571777e1a401c1814.tar.gz
paludis-0b3117db9a5baed87bf08ce571777e1a401c1814.tar.xz
Add --format argument to cave print-owners
-rw-r--r--src/clients/cave/cmd_print_owners.cc45
1 files changed, 41 insertions, 4 deletions
diff --git a/src/clients/cave/cmd_print_owners.cc b/src/clients/cave/cmd_print_owners.cc
index a7b5f22..caa81b5 100644
--- a/src/clients/cave/cmd_print_owners.cc
+++ b/src/clients/cave/cmd_print_owners.cc
@@ -20,13 +20,19 @@
#include "cmd_print_owners.hh"
#include "command_command_line.hh"
+#include "format_string.hh"
#include "owner_common.hh"
#include <paludis/args/args.hh>
#include <paludis/args/do_help.hh>
#include <paludis/dep_spec.hh>
#include <paludis/filter.hh>
+#include <paludis/metadata_key.hh>
+#include <paludis/package_id.hh>
#include <paludis/user_dep_spec.hh>
#include <paludis/util/make_null_shared_ptr.hh>
+#include <paludis/util/map.hh>
+#include <paludis/util/stringify.hh>
+#include <paludis/version_spec.hh>
#include <iostream>
#include <cstdlib>
@@ -59,6 +65,9 @@ namespace
args::EnumArg a_type;
args::StringSetArg a_matching;
+ args::ArgsGroup g_display_options;
+ args::StringArg a_format;
+
PrintOwnersCommandLine() :
g_owner_options(main_options_section(), "Owner options", "Alter how the search is performed."),
a_type(&g_owner_options, "type", 't', "Which type of match algorithm to use",
@@ -70,15 +79,42 @@ namespace
"auto"),
a_matching(&g_owner_options, "matching", 'm', "Show only IDs matching this spec. If specified multiple "
"times, only IDs matching every spec are selected.",
- args::StringSetArg::StringSetArgOptions())
+ args::StringSetArg::StringSetArgOptions()),
+ g_display_options(main_options_section(), "Display Options", "Controls the output format."),
+ a_format(&g_display_options, "format", 'f', "Select the output format. Special tokens recognised are "
+ "%c for category, %p for package, %v for version, %s for slot, %: for ':' if we have a slot and "
+ "empty otherwise, %r for repository, %F for the canonical full form, %V for the canonical full "
+ "version, %W for the canonical full unversioned form, %N for the canonical full unnamed form, "
+ "\\n for newline, \\t for tab. Default is '%F\\n'.")
{
add_usage_line("[ --type algorithm ] [ --matching spec ] pattern");
+ a_format.set_argument("%F\\n");
}
};
- void print_package_id(const std::shared_ptr<const PackageID> & id)
+ std::string format_id(
+ const std::string & format,
+ const std::shared_ptr<const PackageID> & i)
+ {
+ std::shared_ptr<Map<char, std::string> > m(std::make_shared<Map<char, std::string>>());
+ m->insert('c', stringify(i->name().category()));
+ m->insert('p', stringify(i->name().package()));
+ m->insert('v', stringify(i->version()));
+ m->insert('s', i->slot_key() ? stringify(i->slot_key()->parse_value()) : "");
+ m->insert(':', i->slot_key() ? ":" : "");
+ m->insert('r', stringify(i->repository_name()));
+ m->insert('F', i->canonical_form(idcf_full));
+ m->insert('V', i->canonical_form(idcf_version));
+ m->insert('W', i->canonical_form(idcf_no_version));
+ m->insert('N', i->canonical_form(idcf_no_name));
+ return format_string(format, m);
+ }
+
+ void print_package_id(
+ const std::string & format,
+ const std::shared_ptr<const PackageID> & id)
{
- cout << *id << endl;
+ cout << format_id(format, id);
}
}
@@ -113,7 +149,8 @@ PrintOwnersCommand::run(
}
return owner_common(env, cmdline.a_type.argument(), matches,
- *cmdline.begin_parameters(), false, &print_package_id);
+ *cmdline.begin_parameters(), false,
+ std::bind(&print_package_id, cmdline.a_format.argument(), std::placeholders::_1));
}
std::shared_ptr<args::ArgsHandler>