summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Burrows <dburrows@debian.org>2008-06-07 12:48:04 -0700
committerDaniel Burrows <dburrows@debian.org>2008-06-07 12:48:04 -0700
commit76456fd07e12bef4e383e40ec5607d6e2cd3b6a2 (patch)
tree221c957de8507a632747bb659b0576c3a62c276c
parent45f522281d76b07c5ac6c3dfe64fc08c1f94400a (diff)
downloadaptitude-76456fd07e12bef4e383e40ec5607d6e2cd3b6a2.tar.gz
Implement the "disable column formatting" feature via a new command-line option, "--disable-columns". (Closes: #141929)
This should make 'aptitude search' more useful in scripting contexts or other situations where its output is being used noninteractively.
-rw-r--r--doc/en/aptitude.xml18
-rw-r--r--doc/en/manpage.xml48
-rw-r--r--src/cmdline/cmdline_search.cc60
-rw-r--r--src/cmdline/cmdline_search.h3
-rw-r--r--src/main.cc11
5 files changed, 125 insertions, 15 deletions
diff --git a/doc/en/aptitude.xml b/doc/en/aptitude.xml
index e0cfb200..f383fef6 100644
--- a/doc/en/aptitude.xml
+++ b/doc/en/aptitude.xml
@@ -9439,6 +9439,20 @@ iuAU wesnoth-data +930kB 0.8.7-1 0.8.8-1.0w
</seg>
</seglistitem>
+ <seglistitem id='configCmdLine-Disable-Columns'>
+ <seg><literal>Aptitude::CmdLine::Disable-Columns</literal></seg>
+ <seg><literal>false</literal></seg>
+ <seg>
+ If this option is enabled, the results of command-line
+ searches (performed via <literal>aptitude
+ search</literal>) will not be formatted into
+ fixed-width columns or truncated to the screen width.
+ This is equivalent to the <link
+ linkend='cmdlineOptionDisableColumns'><literal>--disable-columns</literal></link>
+ command-line option.
+ </seg>
+ </seglistitem>
+
<seglistitem id='configCmdLine-Download-Only'>
<seg><literal>Aptitude::CmdLine::Download-Only</literal></seg>
<seg><literal>false</literal></seg>
@@ -9629,8 +9643,8 @@ iuAU wesnoth-data +930kB 0.8.7-1 0.8.8-1.0w
<seg><literal>Aptitude::Safe-Resolver::No-New-Installs</literal></seg>
<seg><literal>false</literal></seg>
<seg>
- If this option is enabled, then when the
- <quote>safe</quote> dependency resolver has been
+ If this option is <literal>true</literal>, then when
+ the <quote>safe</quote> dependency resolver has been
activated via <link
linkend='cmdlineSafeResolver'><literal>--safe-resolver</literal></link>,
the resolver will not be allowed to install packages
diff --git a/doc/en/manpage.xml b/doc/en/manpage.xml
index 3f939ee7..e3ae7046 100644
--- a/doc/en/manpage.xml
+++ b/doc/en/manpage.xml
@@ -1006,6 +1006,48 @@ i A texlive-latex-extra Conflicts textopo</screen>
</listitem>
</varlistentry>
+ <varlistentry id='cmdlineOptionDisableColumns'>
+ <term><literal>--disable-columns</literal></term>
+
+ <listitem>
+ <para>
+ This option causes <literal>aptitude search</literal> to
+ output its results without any special formatting. In
+ particular: normally &aptitude; will add whitespace or
+ truncate search results in an attempt to fit its results
+ into vertical <quote>columns</quote>. With this flag,
+ each line will be formed by replacing any format escapes
+ in the format string with the correponding text; column
+ widths will be ignored.
+ </para>
+
+ <para>
+ For instance, the first few lines of output from <quote><literal>aptitude search -F '%p %V' --disable-columns libedataserver</literal></quote> might be:
+ </para>
+
+ <screen>disksearch 1.2.1-3
+hp-search-mac 0.1.3
+libbsearch-ruby 1.5-5
+libbsearch-ruby1.8 1.5-5
+libclass-dbi-abstractsearch-perl 0.07-2
+libdbix-fulltextsearch-perl 0.73-10</screen>
+
+ <para>
+ As in the above example,
+ <literal>--disable-columns</literal> is often useful in
+ combination with a custom display format set using the
+ command-line option <link
+ linkend='cmdlineOptionFormat'><literal>-F</literal></link>.
+ </para>
+
+ <para>
+ This corresponds to the configuration option
+ <literal><link
+ linkend='configCmdLine-Disable-Columns'>Aptitude::CmdLine::Disable-Columns</link></literal>.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><literal>-D</literal>, <literal>--show-deps</literal></term>
@@ -1058,6 +1100,12 @@ i A texlive-latex-extra Conflicts textopo</screen>
</para>
<para>
+ The command-line option <link
+ linkend='cmdlineOptionDisableColumns'><literal>--disable-columns</literal></link>
+ is often useful in combination with <literal>-F</literal>.
+ </para>
+
+ <para>
This corresponds to the configuration option <literal><link linkend='configCmdLine-Package-Display-Format'>Aptitude::CmdLine::Package-Display-Format</link></literal>.
</para>
</listitem>
diff --git a/src/cmdline/cmdline_search.cc b/src/cmdline/cmdline_search.cc
index 45bf3f5f..e76376c9 100644
--- a/src/cmdline/cmdline_search.cc
+++ b/src/cmdline/cmdline_search.cc
@@ -27,8 +27,9 @@ using namespace std;
namespace cw = cwidget;
using cwidget::util::transcode;
using namespace aptitude::matching;
+using namespace cwidget::config;
-class search_result_parameters : public cwidget::config::column_parameters
+class search_result_parameters : public column_parameters
{
pkg_match_result *r;
public:
@@ -91,7 +92,8 @@ public:
// FIXME: apt-cache does lots of tricks to make this fast. Should I?
int cmdline_search(int argc, char *argv[], const char *status_fname,
- string display_format, string width, string sort)
+ string display_format, string width, string sort,
+ bool disable_columns)
{
int real_width=-1;
@@ -123,7 +125,7 @@ int cmdline_search(int argc, char *argv[], const char *status_fname,
return -1;
}
- cwidget::config::column_definition_list *columns =
+ column_definition_list *columns =
parse_columns(wdisplay_format,
pkg_item::pkg_columnizer::parse_column_type,
pkg_item::pkg_columnizer::defaults);
@@ -201,15 +203,53 @@ int cmdline_search(int argc, char *argv[], const char *status_fname,
for(vector<pair<pkgCache::PkgIterator, pkg_match_result *> >::iterator i=output.begin();
i!=output.end(); ++i)
{
- cwidget::config::column_parameters *p =
+ column_parameters *p =
new search_result_parameters(i->second);
+ pkg_item::pkg_columnizer columnizer(i->first,
+ i->first.VersionList(),
+ *columns,
+ 0);
+ if(disable_columns)
+ {
+ // Instantiate the format string without clipping or
+ // expanding columns.
+ //
+ // TODO: this should move into cwidget in the future, as a new
+ // mode of operation for layout_columns().
+ std::wstring output;
+
+ for(column_definition_list::iterator it = columns->begin();
+ it != columns->end();
+ ++it)
+ {
+ if(it->type == column_definition::COLUMN_LITERAL)
+ output += it->arg;
+ else
+ {
+ eassert(it->type == column_definition::COLUMN_GENERATED ||
+ it->type == column_definition::COLUMN_PARAM);
+
+ if(it->type == column_definition::COLUMN_GENERATED)
+ {
+ cwidget::column_disposition disp = columnizer.setup_column(it->ival);
+ output += disp.text;
+ }
+ else
+ {
+ if(p->param_count() <= it->ival)
+ output += L"###";
+ else
+ output += p->get_param(it->ival);
+ }
+ }
+ }
- printf("%ls\n",
- pkg_item::pkg_columnizer(i->first,
- i->first.VersionList(),
- *columns,
- 0).layout_columns(real_width==-1?screen_width:real_width,
- *p).c_str());
+ printf("%ls\n", output.c_str());
+ }
+ else
+ printf("%ls\n",
+ columnizer.layout_columns(real_width==-1?screen_width:real_width,
+ *p).c_str());
// Note that this deletes the whole result, so we can't re-use
// the list.
diff --git a/src/cmdline/cmdline_search.h b/src/cmdline/cmdline_search.h
index ead96a70..284f2601 100644
--- a/src/cmdline/cmdline_search.h
+++ b/src/cmdline/cmdline_search.h
@@ -11,6 +11,7 @@
*/
int cmdline_search(int argc, char *argv[], const char *status_fname,
- std::string display_format, std::string width, std::string sort);
+ std::string display_format, std::string width, std::string sort,
+ bool disable_columns);
#endif // CMDLINE_SEARCH_H
diff --git a/src/main.cc b/src/main.cc
index f105d0eb..d4bd2107 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -207,7 +207,8 @@ enum {
OPTION_SAFE_RESOLVER,
OPTION_FULL_RESOLVER,
OPTION_ARCH_ONLY,
- OPTION_NOT_ARCH_ONLY
+ OPTION_NOT_ARCH_ONLY,
+ OPTION_DISABLE_COLUMNS
};
int getopt_result;
@@ -230,6 +231,7 @@ option opts[]={
{"prompt", 0, NULL, 'P'},
{"sort", 1, NULL, 'O'},
{"target-release", 1, NULL, 't'},
+ {"disable-columns", 0, &getopt_result, OPTION_DISABLE_COLUMNS},
{"no-new-installs", 0, &getopt_result, OPTION_NO_NEW_INSTALLS},
{"no-new-upgrades", 0, &getopt_result, OPTION_NO_NEW_UPGRADES},
{"allow-new-installs", 0, &getopt_result, OPTION_ALLOW_NEW_INSTALLS},
@@ -282,6 +284,7 @@ int main(int argc, char *argv[])
bool safe_resolver_no_new_installs = aptcfg->FindB(PACKAGE "::Safe-Resolver::No-New-Installs", false);
bool safe_resolver_no_new_upgrades = aptcfg->FindB(PACKAGE "::Safe-Resolver::No-New-Upgrades", false);
bool always_use_safe_resolver = aptcfg->FindB(PACKAGE "::Always-Use-Safe-Resolver", false);
+ bool disable_columns = aptcfg->FindB(PACKAGE "::CmdLine::Disable-Columns", false);
bool safe_resolver_option = false;
bool full_resolver_option = false;
@@ -520,6 +523,9 @@ int main(int argc, char *argv[])
case OPTION_ARCH_ONLY:
arch_only = true;
break;
+ case OPTION_DISABLE_COLUMNS:
+ disable_columns = true;
+ break;
default:
fprintf(stderr, "%s",
_("WEIRDNESS: unknown option code received\n"));
@@ -599,7 +605,8 @@ int main(int argc, char *argv[])
return cmdline_search(argc-optind, argv+optind,
status_fname,
display_format, width,
- sort_policy);
+ sort_policy,
+ disable_columns);
else if(!strcasecmp(argv[optind], "why"))
return cmdline_why(argc - optind, argv + optind,
status_fname, verbose, false);