Mercurial > hg > Members > anatofuz > slides
comparison lib/CLI.pm @ 40:b887347d2d2b
auto-Update generated slides by script
author | Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 08 May 2018 10:16:46 +0900 |
parents | 202d1ab8775a |
children | deed6fa2e489 |
comparison
equal
deleted
inserted
replaced
39:202d1ab8775a | 40:b887347d2d2b |
---|---|
21 my($self,@args) = @_; | 21 my($self,@args) = @_; |
22 my $opt = Smart::Options->new->options( | 22 my $opt = Smart::Options->new->options( |
23 file => { describe => 'target file', alias => 'f'} | 23 file => { describe => 'target file', alias => 'f'} |
24 ); | 24 ); |
25 $opt->subcmd( | 25 $opt->subcmd( |
26 new => Smart::Options->new(), | 26 new => Smart::Options->new(), |
27 build => Smart::Options->new(), | 27 build => Smart::Options->new(), |
28 open => Smart::Options->new->default('target' => 'slide.md'), | 28 open => Smart::Options->new->default('target' => 'slide.md'), |
29 'build_open' => Smart::Options->new->default('target' => 'slide.md'), | 29 build_open => Smart::Options->new->default('target' => 'slide.md'), |
30 upload => Smart::Options->new(), | 30 upload => Smart::Options->new(), |
31 memo => Smart::Options->new(), | 31 memo => Smart::Options->new(), |
32 edit => Smart::Options->new(), | 32 edit => Smart::Options->new(), |
33 zip => Smart::Options->new(), | 33 zip => Smart::Options->new(), |
34 ); | 34 ); |
35 | 35 |
36 my $result = $opt->parse(@args); | 36 my $result = $opt->parse(@args); |
37 my $command = $result->{command} // "open"; | 37 my $command = $result->{command} // "open"; |
38 | 38 |
39 my $option = $result->{cmd_option}->{f} || $result->{cmd_option}->{file} || 0; | 39 my $option = $result->{cmd_option}->{f} || $result->{cmd_option}->{file} || 0; |
40 | 40 |
41 my $call= $self->can("cmd_$command"); | 41 my $call = $self->can("cmd_$command"); |
42 croak 'undefine subcommand' unless $call; | 42 croak 'undefine subcommand' unless $call; |
43 $self->$call($option); | 43 $self->$call($option); |
44 } | 44 } |
45 | 45 |
46 sub cmd_new { | 46 sub cmd_new { |
47 my ($self) = @_; | 47 my ($self) = @_; |
48 my ($y,$m,$d) = _y_m_d(); | 48 my ($y,$m,$d) = _y_m_d(); |
49 my $slide = path($self->root_dir)->child($y)->child($m)->child($d)->child('slide.md')->touchpath; | 49 my $slide = path($self->root_dir)->child($y)->child($m)->child($d)->child('slide.md')->touchpath; |
50 path($self->template)->copy($slide); | 50 path($self->template)->copy($slide); |
51 } | 51 } |
52 | 52 |
53 sub cmd_build { | 53 sub cmd_build { |
54 my($self,$target) = @_; | 54 my($self,$target) = @_; |
138 # ex... 2018/02/14 | 138 # ex... 2018/02/14 |
139 ($t->strftime('%Y'), $t->strftime('%m'), $t->strftime('%d')); | 139 ($t->strftime('%Y'), $t->strftime('%m'), $t->strftime('%d')); |
140 } | 140 } |
141 | 141 |
142 sub _search_recently_day { | 142 sub _search_recently_day { |
143 my($self) = @_; | 143 my ($self) = @_; |
144 my ($y,$m,$d) = _y_m_d(); | 144 my ($y,$m,$d) = _y_m_d(); |
145 my $root_dir = path($self->root_dir)->child($y)->child($m); | 145 my $root_dir = path($self->root_dir)->child($y)->child($m); |
146 | 146 |
147 my $date = shift @{ [sort { $b->stat->mtime <=> $a->stat->mtime } $root_dir->children]}; | 147 my $date = shift @{ [sort { $b->stat->mtime <=> $a->stat->mtime } $root_dir->children]}; |
148 return $date; | 148 return $date; |
149 } | 149 } |
150 | 150 |
151 sub cmd_memo { | 151 sub cmd_memo { |
152 my ($self) = @_; | 152 my ($self) = @_; |
153 my ($y,$m,$d) = _y_m_d(); | 153 my ($y,$m,$d) = _y_m_d(); |
154 my $memo = path($self->root_dir)->child($y)->child($m)->child($d)->child('memo.txt')->touchpath; | 154 my $memo = path($self->root_dir)->child($y)->child($m)->child($d)->child('memo.txt')->touchpath; |
155 exec $ENV{EDITOR},($memo->realpath); | 155 exec $ENV{EDITOR},($memo->realpath); |
156 } | 156 } |
157 | 157 |
158 sub cmd_edit { | 158 sub cmd_edit { |
159 my ($self) = @_; | 159 my ($self) = @_; |
160 my $recent_day = $self->_search_recently_day(); | 160 my $recent_day = $self->_search_recently_day(); |
161 my @targets = $recent_day->children(qr/\.md$/); | 161 my @targets = $recent_day->children(qr/\.md$/); |
162 my $target = pop @targets; | 162 my $target = pop @targets; |
163 exec $ENV{EDITOR},($target->realpath); | 163 exec $ENV{EDITOR},($target->realpath); |
164 } | 164 } |
165 | 165 |
166 sub cmd_zip { | 166 sub cmd_zip { |
167 my ($self) = @_; | 167 my ($self) = @_; |
185 say $zip "----------"; | 185 say $zip "----------"; |
186 $t += ONE_DAY; | 186 $t += ONE_DAY; |
187 } | 187 } |
188 } | 188 } |
189 | 189 |
190 | |
191 1; | 190 1; |