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:
parent
ee82738f0a
commit
10d809c180
2 changed files with 24 additions and 8 deletions
|
@ -5,6 +5,8 @@
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
|
use IPC::Shareable;
|
||||||
|
|
||||||
our %BEANCOUNT_QUERY;
|
our %BEANCOUNT_QUERY;
|
||||||
|
|
||||||
my $IPC_GLUE = 'BeAn';
|
my $IPC_GLUE = 'BeAn';
|
||||||
|
|
|
@ -198,7 +198,8 @@ while (1) {
|
||||||
$query{fifoName} = mktemp("REJECTED_beancount-query-fifo-this-file-does-not-exist_${$}_XXXXXXXXX");
|
$query{fifoName} = mktemp("REJECTED_beancount-query-fifo-this-file-does-not-exist_${$}_XXXXXXXXX");
|
||||||
(tied %query)->shunlock;
|
(tied %query)->shunlock;
|
||||||
} elsif (not defined $query{fifoName}) {
|
} elsif (not defined $query{fifoName}) {
|
||||||
if (defined $query{format} and $query{format} ne 'text') {
|
if (defined $query{format}) {
|
||||||
|
unless ($query{format} =~ /^(?:text|csv)$/) {
|
||||||
print STDERR "format string $query{format} is not supported yet!\n";
|
print STDERR "format string $query{format} is not supported yet!\n";
|
||||||
(tied %query)->shlock;
|
(tied %query)->shlock;
|
||||||
$query{question} = $query{format} = undef;
|
$query{question} = $query{format} = undef;
|
||||||
|
@ -206,6 +207,18 @@ while (1) {
|
||||||
(tied %query)->shunlock;
|
(tied %query)->shunlock;
|
||||||
next;
|
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;
|
print STDERR "Runing query: $query{question}\n" if $VERBOSE > 0;
|
||||||
my $ques = $query{question};
|
my $ques = $query{question};
|
||||||
$ques =~ s/\n/ /gm;
|
$ques =~ s/\n/ /gm;
|
||||||
|
@ -237,7 +250,8 @@ while (1) {
|
||||||
unless ($seenSeperator) {
|
unless ($seenSeperator) {
|
||||||
if ($line =~ /^\s*$/) {
|
if ($line =~ /^\s*$/) {
|
||||||
$seenSeperator = 1;
|
$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;
|
$seenSeperator = 1;
|
||||||
}
|
}
|
||||||
$prevLine = $line;
|
$prevLine = $line;
|
||||||
|
|
Loading…
Reference in a new issue