From e3541feec258bc63e2cf5ac387e264816a4bf278 Mon Sep 17 00:00:00 2001 From: Charles McGarvey Date: Sat, 9 Nov 2019 15:34:34 -0700 Subject: [PATCH] use Text::Table::Any for table formatting --- bin/git-codeowners | 16 ++++++++++++++-- lib/App/Codeowners.pm | 11 +++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/bin/git-codeowners b/bin/git-codeowners index d565192..60e79b2 100755 --- a/bin/git-codeowners +++ b/bin/git-codeowners @@ -104,12 +104,14 @@ The C<--format> argument can be one of: * C - Comma-separated values (requires L) * C - Pretty JSON (requires L) * C - JSON (requires L) -* C - Table (requires L) +* C
- Table (requires L) * C - Tab-separated values (requires L) * C - YAML (requires L) * C - Custom format (see below) -You can specify a custom format using printf-like format sequences. These are the items that can +=head2 Custom + +You can specify a custom format using printf-like format sequences. These are the items that can be substituted: =for :list @@ -134,6 +136,16 @@ Available filters: * C - Colorize the replacement string (if color is ON). * C - Do not colorize replacement string. +=head2 Table + +Table formatting can be done by one of several different modules, each with its own features and +bugs. The default module is L, but this can be overridden using the +C environment variable if desired, like this: + + PERL_TEXT_TABLE=Text::Table::HTML git-codeowners -f table + +The list of available modules is at L. + =cut # FATPACK - Do not remove this line. diff --git a/lib/App/Codeowners.pm b/lib/App/Codeowners.pm index efe86f7..113a3a1 100644 --- a/lib/App/Codeowners.pm +++ b/lib/App/Codeowners.pm @@ -174,11 +174,14 @@ sub _format { my $rows = $args{rows} || []; if ($format eq 'table') { - eval { require Text::Table } or die "Missing dependency: Text::Table\n"; + eval { require Text::Table::Any } or die "Missing dependency: Text::Table::Any\n"; - my $table = Text::Table->new(@$headers); - $table->load(map { [map { _stringify($_) } @$_] } @$rows); - print { $fh } encode('UTF-8', "$table"); + my $table = Text::Table::Any::table( + header_row => 1, + rows => [$headers, map { [map { _stringify($_) } @$_] } @$rows], + backend => $ENV{PERL_TEXT_TABLE}, + ); + print { $fh } encode('UTF-8', $table); } elsif ($format =~ /^json(:pretty)?$/) { my $pretty = !!$1; -- 2.45.2