diff --git a/phosta.pl b/phosta.pl
index 1e4d1738e8a2e71e7b10ed8010842db713213583..3a175122e47ee166746dad077a11cee0954e3afa 100755
--- a/phosta.pl
+++ b/phosta.pl
@@ -38,10 +38,11 @@ our $opt_r=0;
our $opt_f=undef;
our $opt_e=0;
our $opt_W=80;
+our $opt_T='auto';
getconfig();
-getopts('vcrp:n:g:s:t:D:E:o:f:eW:') or die "Invalid parameters provided! See 'phosta --help' for more details.";
+getopts('vcrp:n:g:s:t:D:E:o:f:eW:T:') or die "Invalid parameters provided! See 'phosta --help' for more details.";
validate() or die "Invalid parameters provided! See 'phosta --help' for more details.";
my $dsn = "DBI:SQLite:dbname=$opt_D";
@@ -61,10 +62,10 @@ exit 0;
sub validate
{
- my @group_params = ('year', 'month', 'week', 'hour');
+ my @group_params = qw(year month week hour);
!defined($opt_g) || $opt_g ~~ @group_params or return 0;
- my @select_params = ('file', 'maker', 'model', 'lensmake', 'lens', 'aperture', 'exposuretime', 'iso', 'focallength', 'focallength35mm', '');
+ my @select_params = qw(file maker model lensmake lens aperture exposuretime iso focallength focallength35mm);
if (defined($opt_s))
{
foreach (split (/,/, $opt_s))
@@ -89,6 +90,9 @@
$opt_E =~ /^([a-z]{2,4}){1,}(\,[a-z]{2,4}){0,}$/ or return 0;
!defined($opt_f) || $opt_f =~ /^(,{0,1}[\w\-]{2,}(!){0,1}=[\w\-\s]{1,}){1,}$/ or return 0;
+
+ my @table_params = qw(on off auto);
+ $opt_T ~~ @table_params or return 0;
return 1;
}
@@ -103,6 +107,7 @@ open(my $filehandle, '>', $configfile) or die "Could not open file '$configfile': $!";
say $filehandle '$opt_D="'. $opt_D .'";';
say $filehandle '$opt_E="'. $opt_E .'";';
say $filehandle '$opt_W="'. $opt_W .'";';
+ say $filehandle '$opt_T="'. $opt_T .'";';
close $filehandle;
}
@@ -312,8 +317,14 @@
my ($limited_rows, $skippedlines) = limit_results($rows);
print_filterinfo(scalar @$limited_rows, $skippedlines, $sum);
- if (@$headers == 3) { result_to_graph($headers, $limited_rows, $sum); }
- else { result_to_table($headers, $limited_rows, $sum); }
+ if ($opt_T eq 'off' || (@$headers == 3 and $opt_T eq 'auto') )
+ {
+ result_to_graph($headers, $limited_rows, $sum);
+ }
+ else
+ {
+ result_to_table($headers, $limited_rows, $sum);
+ }
}
sub limit_results
@@ -386,10 +397,13 @@
my $barwidth = POSIX::lround(($opt_W - 17) * 0.7);
my $titlewidth = POSIX::lround(($opt_W - 17) * 0.3);
my $chartformat = '%'.$titlewidth.'.'.$titlewidth.'s |%-'.$barwidth.'s| %5s (%s)';
-
+
+ my $countcolumn = @$headers - 2;
+ my $percentcolumn = @$headers - 1;
+
foreach (@$rows)
{
- say sprintf($chartformat, @$_[0], "*"x(50/$sum*@$_[1]), @$_[2], @$_[1]);
+ say sprintf($chartformat, @$_[0], "*"x(50/$sum*@$_[$countcolumn]), @$_[$percentcolumn], @$_[$countcolumn]);
}
}
@@ -454,6 +468,9 @@ say ' allowed values: any comma separated combination of the values of -t and -s param and \'count\'';
say ' -r : sort in reverse (ascending) order, default is descending order';
say ' -e : skip lines with empty selected or grouping fields';
say ' -W <number> : define max char width of output, default: 80, a minimum of 50 is required for meaningful output';
+ say ' This option is automatically saved to the user config.';
+ say ' -T <value> : show results as always as a table (on) or not (off) or auto (chart when single field is selected), default is auto';
+ say ' allowed values: auto, on, off';
say ' This option is automatically saved to the user config.';
say '';
say 'examples:';