Restore support for csv output format.

I took a shortcut on some previous changes and it led to only text
format being supported.  These changes bring back support for csv.
This commit is contained in:
Bradley M. Kuhn 2020-09-25 10:49:34 -07:00
parent ee82738f0a
commit 10d809c180
No known key found for this signature in database
GPG key ID: F15E8BD6D05E26B3
2 changed files with 24 additions and 8 deletions

View file

@ -5,6 +5,8 @@
use strict;
use warnings;
use IPC::Shareable;
our %BEANCOUNT_QUERY;
my $IPC_GLUE = 'BeAn';

View file

@ -198,13 +198,26 @@ while (1) {
$query{fifoName} = mktemp("REJECTED_beancount-query-fifo-this-file-does-not-exist_${$}_XXXXXXXXX");
(tied %query)->shunlock;
} elsif (not defined $query{fifoName}) {
if (defined $query{format} and $query{format} ne 'text') {
print STDERR "format string $query{format} is not supported yet!\n";
(tied %query)->shlock;
$query{question} = $query{format} = undef;
$query{fifoName} = mktemp("REJECTED_beancount-$query{format}_not_supported_${$}_XXXXXXXXX");
(tied %query)->shunlock;
next;
if (defined $query{format}) {
unless ($query{format} =~ /^(?:text|csv)$/) {
print STDERR "format string $query{format} is not supported yet!\n";
(tied %query)->shlock;
$query{question} = $query{format} = undef;
$query{fifoName} = mktemp("REJECTED_beancount-$query{format}_not_supported_${$}_XXXXXXXXX");
(tied %query)->shunlock;
next;
}
if ($currentFormat ne $query{format}) {
$runningBeanQuery->send("set format $query{format}\n");
$runningBeanQuery->expect(undef, 'beancount>') # *Don't* use regex here!
or die("Unable to find beancount prompt, output was instead: ".
$runningBeanQuery->before() . $runningBeanQuery->after());
$currentFormat = $query{format};
print STDERR "Switched formats to the $currentFormat..." if $VERBOSE > 3;
my $rbcBefore = $runningBeanQuery->before();
die("Unable to change format to $currentFormat")
unless $rbcBefore =~ /format\s*:\s*$currentFormat/ixm;
}
}
print STDERR "Runing query: $query{question}\n" if $VERBOSE > 0;
my $ques = $query{question};
@ -237,7 +250,8 @@ while (1) {
unless ($seenSeperator) {
if ($line =~ /^\s*$/) {
$seenSeperator = 1;
} elsif ($currentFormat eq 'text' and $line =~ /^\s*[\-\s]+\s*$/) {
} elsif (($currentFormat eq 'text' and $line =~ /^\s*[\-\s]+\s*$/)
or ($currentFormat eq 'csv' and $line =~ /^\s*(\S+,)*\S+\s*$/)){
$seenSeperator = 1;
}
$prevLine = $line;