File tree Expand file tree Collapse file tree 3 files changed +45
-0
lines changed
Expand file tree Collapse file tree 3 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ const program = require ( 'commander' ) ;
2+ const colors = require ( 'colors' ) ;
3+ const moment = require ( 'moment' ) ;
4+
5+ const Config = require ( './include/file-config' ) ;
6+ const Cli = require ( './include/cli' ) ;
7+ const Tasks = require ( './include/tasks' ) ;
8+
9+ program
10+ . option ( '--verbose' , 'show verbose output' )
11+ . parse ( process . argv ) ;
12+
13+ Cli . verbose = program . verbose ;
14+
15+ let config = new Config ( process . cwd ( ) ) ,
16+ tasks = new Tasks ( config ) ;
17+
18+
19+ tasks . resume ( )
20+ . then ( frame => console . log ( `Starting project ${ config . get ( 'project' ) . magenta } ${ frame . resource . type . blue } ${ ( '#' + frame . resource . id ) . blue } at ${ moment ( ) . format ( 'HH:mm' ) . green } ` ) )
21+ . catch ( error => Cli . error ( error ) ) ;
Original file line number Diff line number Diff line change 99 . command ( 'create [project] [title]' , 'start monitoring time for the given project and create a new issue or merge request with the given title' )
1010 . command ( 'status' , 'shows if time monitoring is running' )
1111 . command ( 'stop' , 'stop monitoring time' )
12+ . command ( 'resume' , 'resume monitoring time for last stopped record' )
1213 . command ( 'cancel' , 'cancel and discard active monitoring time' )
1314 . command ( 'log' , 'log recorded time records' )
1415 . command ( 'sync' , 'sync local time records to GitLab' )
Original file line number Diff line number Diff line change @@ -174,6 +174,29 @@ class tasks {
174174 } ) ;
175175 }
176176
177+ /**
178+ *
179+ * @returns {Promise }
180+ */
181+ resume ( ) {
182+ return new Promise ( ( resolve , reject ) => {
183+ let project ;
184+ let frames = new FrameCollection ( this . config ) . frames
185+ if ( project = this . config . get ( 'project' ) ) {
186+ frames = frames . filter ( frame => frame . project == project )
187+ }
188+ const last = frames . filter ( frame => frame . stop )
189+ . sort ( ( a , b ) => - 1 * a . stop . localeCompare ( b . stop ) ) [ 0 ]
190+ if ( last ) {
191+ this . start ( last . project , last . resource . type , last . resource . id )
192+ . then ( frames => resolve ( frames ) )
193+ . catch ( error => reject ( error ) )
194+ } else {
195+ reject ( "No recent entry found for project" )
196+ }
197+ } ) ;
198+ }
199+
177200 /**
178201 *
179202 * @param project
You can’t perform that action at this time.
0 commit comments