Browse Source

stub wrt-ls

Brennen Bearnes 7 months ago
parent
commit
95dfd5b21c
1 changed files with 113 additions and 0 deletions
  1. 113
    0
      bin/wrt-ls

+ 113
- 0
bin/wrt-ls View File

@@ -0,0 +1,113 @@
1
+#!/usr/bin/env perl
2
+
3
+=pod
4
+
5
+=head1 NAME
6
+
7
+wrt-ls - list 
8
+
9
+=head1 USAGE
10
+
11
+    wrt ls          # all entries
12
+    wrt ls 2016     # all entries for 2016
13
+    wrt ls 2016/4   # all entries for April 2016
14
+    wrt ls 2016/4/1 # everything for April 1, 2016
15
+    wrt ls --days   # entries for individual days
16
+    wrt ls --months # entries for individual months 
17
+    wrt ls --years  # entries for years
18
+
19
+    # Display help:
20
+    wrt ls --help
21
+
22
+    # Specify a different config file:
23
+    wrt ls --config ./wrt.json ...
24
+
25
+=head1 DESCRIPTION
26
+
27
+Lists entries in the current wrt archive.
28
+
29
+Detailed documentation can be found in the L<App::WRT> man page or at
30
+L<https://code.p1k3.com/gitea/brennen/wrt>.
31
+
32
+=head1 LICENSE
33
+
34
+    wrt is free software; you can redistribute it and/or modify
35
+    it under the terms of the GNU General Public License as published by
36
+    the Free Software Foundation; either version 2 of the License, or
37
+    (at your option) any later version.
38
+
39
+=head1 AUTHOR
40
+
41
+Brennen Bearnes <code@p1k3.com>
42
+
43
+=cut
44
+
45
+use 5.10.0;
46
+
47
+use strict;
48
+use warnings;
49
+no  warnings 'uninitialized';
50
+
51
+use Getopt::Long;
52
+use Pod::Usage;
53
+use App::WRT;
54
+
55
+# Handle options, including help generated from the POD above.  See:
56
+# - http://perldoc.perl.org/Getopt/Long.html#User-defined-subroutines-to-handle-options
57
+# - https://metacpan.org/pod/Pod::Usage
58
+# - http://michael.thegrebs.com/2014/06/08/Pod-Usage/
59
+my $config_file = 'wrt.json';
60
+my $list_days = 0;
61
+my $list_months = 0;
62
+my $list_years = 0;
63
+my $list_all = 1;
64
+GetOptions(
65
+  'config=s' => \$config_file,
66
+  help       => sub { pod2usage(0) },
67
+  days       => \$list_days,
68
+  months     => \$list_months,
69
+  years      => \$list_years,
70
+) or pod2usage(2);
71
+
72
+# Allow only one of --days, --months, --years.  Default to listing all entries
73
+# if none of these are specified.
74
+my $option_count = 0;
75
+foreach ($list_days, $list_months, $list_years) {
76
+  $option_count += $_;
77
+}
78
+if ($option_count > 1) {
79
+  die "Please specify at most one of --days, --months, or --years.";
80
+} elsif ($option_count == 1) {
81
+  $list_all = 0;
82
+}
83
+
84
+unless (-e $config_file) {
85
+  die "No wrt config file found.  Tried: $config_file";
86
+}
87
+
88
+my $w = App::WRT::new_from_file($config_file);
89
+
90
+# Did we get any patterns to match against?
91
+if (@ARGV) {
92
+  
93
+}
94
+
95
+if ($list_days) {
96
+  foreach my $entry ($w->{entries}->all_days()) {
97
+    say $entry;
98
+  }
99
+} elsif ($list_months) {
100
+  foreach my $entry ($w->{entries}->all_months()) {
101
+    say $entry;
102
+  }
103
+} elsif ($list_years) {
104
+  foreach my $entry ($w->{entries}->all_years()) {
105
+    say $entry;
106
+  }
107
+} elsif ($list_all) {
108
+  foreach my $entry ($w->{entries}->all()) {
109
+    say $entry;
110
+  }
111
+}
112
+
113
+exit(0);

Loading…
Cancel
Save