@@ -13,6 +13,7 @@ program
1313 . option ( '--verbose' , 'show verbose output' )
1414 . option ( '--hours_per_day <hours>' , 'hours per day for human readable time formats' )
1515 . option ( '--time_format <time_format>' , 'time format' )
16+ . option ( '--csv' , 'comma separated output' )
1617 . parse ( process . argv ) ;
1718
1819Cli . verbose = program . opts ( ) . verbose ;
@@ -32,38 +33,52 @@ function column(str, n){
3233 return str . padEnd ( n ) ;
3334 } ;
3435
35-
36- tasks . log ( )
37- . then ( ( { frames, times} ) => {
38- Object . keys ( frames ) . sort ( ) . forEach ( date => {
39- if ( ! frames . hasOwnProperty ( date ) ) return ;
40- let dayNote = "" ;
41- let hpd = config . get ( 'hoursPerDay' ) ;
42- if ( times [ date ] > hpd * 3600 * 2 )
43- {
44- dayNote = ` - worked over ${ hpd * 2 } hours` . red ;
45- } else if ( times [ date ] > hpd * 3600 * 1.5 )
46- {
47- dayNote = ` - worked over ${ hpd * 1.5 } hours` . yellow ;
48- } else if ( times [ date ] > hpd * 3600 * 1.1 )
49- {
50- dayNote = ` - worked over ${ hpd * 1.1 } hours` . green ;
51- }
52-
36+ const logCSV = ( frames , times ) => {
37+ console . log ( "frameId, project, issueid, date, starttime, endtime, duration (s), title, note" ) ;
38+ Object . keys ( frames ) . sort ( ) . forEach ( date => {
39+ if ( ! frames . hasOwnProperty ( date ) ) return ;
40+ frames [ date ] . sort ( ( a , b ) => a . start . isBefore ( b . start ) ? - 1 : 1 )
41+ . forEach ( frame => {
42+ console . log ( `${ frame . id } , ${ frame . project } , ${ frame . resource . id } , ${ moment ( date ) . format ( 'YYYY-MM-DD' ) } , ${ frame . start . clone ( ) . format ( 'HH:mm' ) } , ${ frame . stop . clone ( ) . format ( 'HH:mm' ) } , ${ frame . duration } , ${ frame . title != null ?frame . title :'' } , ${ frame . note != null ?frame . note :'' } ` ) ;
43+ } ) ;
44+ } ) ;
45+ } ;
46+
47+ const logCli = ( frames , times ) => {
48+ Object . keys ( frames ) . sort ( ) . forEach ( date => {
49+ if ( ! frames . hasOwnProperty ( date ) ) return ;
50+
51+ let dayNote = "" ;
52+ let hpd = config . get ( 'hoursPerDay' ) ;
53+ if ( times [ date ] > hpd * 3600 * 2 )
54+ {
55+ dayNote = ` - worked over ${ hpd * 2 } hours` . red ;
56+ } else if ( times [ date ] > hpd * 3600 * 1.5 )
57+ {
58+ dayNote = ` - worked over ${ hpd * 1.5 } hours` . yellow ;
59+ } else if ( times [ date ] > hpd * 3600 * 1.1 )
60+ {
61+ dayNote = ` - worked over ${ hpd * 1.1 } hours` . green ;
62+ }
63+
5364
54- console . log ( `${ moment ( date ) . format ( 'MMMM Do YYYY' ) } (${ toHumanReadable ( times [ date ] ) } )` . green + dayNote ) ;
55- frames [ date ]
56- . sort ( ( a , b ) => a . start . isBefore ( b . start ) ? - 1 : 1 )
57- . forEach ( frame => {
58- let toSync = ( Math . ceil ( frame . duration ) - parseInt ( _ . reduce ( frame . notes , ( n , m ) => ( n + m . time ) , 0 ) ) ) != 0 ;
59- let durationText = toSync ? toHumanReadable ( frame . duration ) . padEnd ( 14 ) . yellow : toHumanReadable ( frame . duration ) . padEnd ( 14 ) ;
60- let issue = frame . resource . new ?
61- column ( `(new ${ frame . resource . type + ' "' + frame . resource . id } ")` , 70 ) . bgBlue :
62- `${ ( frame . resource . type + ' #' + frame . resource . id ) . padEnd ( 20 ) . blue } ${ column ( frame . title != null ?frame . title :'' , 50 ) } ` ;
63- console . log ( ` ${ frame . id } ${ frame . start . clone ( ) . format ( 'HH:mm' ) . green } to ${ frame . stop . clone ( ) . format ( 'HH:mm' ) . green } \t${ durationText } ` +
64- `${ column ( frame . project , 50 ) . magenta } ${ issue } ${ frame . note != null ?frame . note :'' } ` ) ;
65- } ) ;
65+ console . log ( `${ moment ( date ) . format ( 'MMMM Do YYYY' ) } (${ toHumanReadable ( times [ date ] ) } )` . green + dayNote ) ;
66+ frames [ date ]
67+ . sort ( ( a , b ) => a . start . isBefore ( b . start ) ? - 1 : 1 )
68+ . forEach ( frame => {
69+ let toSync = ( Math . ceil ( frame . duration ) - parseInt ( _ . reduce ( frame . notes , ( n , m ) => ( n + m . time ) , 0 ) ) ) != 0 ;
70+ let durationText = toSync ? toHumanReadable ( frame . duration ) . padEnd ( 14 ) . yellow : toHumanReadable ( frame . duration ) . padEnd ( 14 ) ;
71+ let issue = frame . resource . new ?
72+ column ( `(new ${ frame . resource . type + ' "' + frame . resource . id } ")` , 70 ) . bgBlue :
73+ `${ ( frame . resource . type + ' #' + frame . resource . id ) . padEnd ( 20 ) . blue } ${ column ( frame . title != null ?frame . title :'' , 50 ) } ` ;
74+ console . log ( ` ${ frame . id } ${ frame . start . clone ( ) . format ( 'HH:mm' ) . green } to ${ frame . stop . clone ( ) . format ( 'HH:mm' ) . green } \t${ durationText } ` +
75+ `${ column ( frame . project , 50 ) . magenta } ${ issue } ${ frame . note != null ?frame . note :'' } ` ) ;
6676 } ) ;
67- }
68- )
77+ } ) ;
78+ } ;
79+
80+ const log = program . opts ( ) . csv ? logCSV : logCli ;
81+
82+ tasks . log ( )
83+ . then ( ( { frames, times} ) => log ( frames , times ) )
6984 . catch ( error => Cli . error ( error ) ) ;
0 commit comments