Browse Source

commandlog-log: add --debug flag

Prints query and bound values to STDERR.
Brennen Bearnes 3 months ago
parent
commit
d21dea7761
3 changed files with 14 additions and 1 deletions
  1. 1
    0
      Build.PL
  2. 12
    0
      bin/commandlog-log
  3. 1
    1
      lib/App/CommandLog.pm

+ 1
- 0
Build.PL View File

@@ -7,6 +7,7 @@ my $build = Module::Build->new(
7 7
   license  => 'gpl',
8 8
 
9 9
   requires => {
10
+    'Data::Dumper'  => 0,
10 11
     'File::Spec'    => 0,
11 12
     'Getopt::Long'  => 0,
12 13
     'POSIX'         => 0,

+ 12
- 0
bin/commandlog-log View File

@@ -23,6 +23,9 @@ commandlog-log - show commandlog history
23 23
     # Get entries for the current directory:
24 24
     commandlog log --path .
25 25
 
26
+    # Run some query with debugging output enabled:
27
+    commandlog log --debug [...]
28
+
26 29
 =head1 AUTHOR
27 30
 
28 31
 Brennen Bearnes
@@ -34,6 +37,7 @@ use strict;
34 37
 use 5.10.0;
35 38
 
36 39
 use Cwd;
40
+use Data::Dumper;
37 41
 use DBI;
38 42
 use File::Spec;
39 43
 use Getopt::Long;
@@ -44,11 +48,13 @@ use Sys::Hostname;
44 48
 use App::CommandLog;
45 49
 
46 50
 # Handle options, including help generated from the POD above.
51
+my $debug = 0;
47 52
 my $limit;
48 53
 my $before_date;
49 54
 my $after_date;
50 55
 my $path;
51 56
 GetOptions(
57
+  'debug'    => \$debug,
52 58
   'number=s' => \$limit,
53 59
   'before=s' => \$before_date,
54 60
   'after=s'  => \$after_date,
@@ -102,6 +108,12 @@ my ($query, @bind) = $sql->select(
102 108
   {-desc => 'datetime'}
103 109
 );
104 110
 
111
+if ($debug) {
112
+  say STDERR $query . $limit_clause;
113
+  say STDERR Dumper(%where);
114
+  say STDERR Dumper(@bind);
115
+}
116
+
105 117
 my $sth = $dbh->prepare($query . $limit_clause);
106 118
 $sth->execute(@bind);
107 119
 

+ 1
- 1
lib/App/CommandLog.pm View File

@@ -14,7 +14,7 @@ App::CommandLog - Tools for logging command line history
14 14
 
15 15
 package App::CommandLog;
16 16
 
17
-our ($VERSION) = '0.3.0';
17
+our ($VERSION) = '0.4.0';
18 18
 
19 19
 use strict;
20 20
 use warnings;

Loading…
Cancel
Save