@@ -16,18 +16,32 @@ program
1616 . version ( pkg . version )
1717 . arguments ( '[timeEntryId] [note]' )
1818 . description (
19- 'Rewrite the note for the given time entry id or use the currently ' +
20- 'running time entry and edit it’s note' ,
19+ `Updates the note of the currently tracked time entry (when no id is given) \
20+ or the one specified in the first argument. The content of the note can be \
21+ second argument or piped into the program. See the examples for the different \
22+ usages.
23+
24+ Also the project id and service id of a time entry can be altered if the user \
25+ has the required permissions to do it.` ,
2126 {
22- timeEntryId : 'optional id of the time entry that should be altered, ' +
23- 'if not given the currently running entry is used' ,
27+ timeEntryId :
28+ 'optional id of the time entry that should be altered, if not given ' +
29+ 'the currently running entry is used' ,
2430 note : 'optional value to which the time entries note should be set'
2531 }
2632 )
2733 . option (
2834 '-e, --editor' ,
2935 'open preferred $EDITOR for editing'
3036 )
37+ . option (
38+ '--project-id <id>' ,
39+ 'the project id which should be set'
40+ )
41+ . option (
42+ '--service-id <id>' ,
43+ 'the service id which should be set'
44+ )
3145 . on ( '--help' , ( ) => console . log ( `
3246Examples:
3347
@@ -42,9 +56,21 @@ Examples:
4256
4357 Change the note via command line argument:
4458 mite amend 12345678 "created a programmable list of items"
59+
60+ If you leave out the id the currently tracked note will be changed
61+ mite amend "created a programmable list of items"
62+
63+ Change project and service
64+ mite amend 12345678 --service-id 918772 --project-id 129379
4565 ` ) ) ;
4666
4767function main ( timeEntryId , note ) {
68+ // if first argument is the note instead of the timeEntry
69+ if ( ! note && ! timeEntryId . match ( / ^ \d + / ) ) {
70+ note = timeEntryId ;
71+ timeEntryId = undefined ;
72+ }
73+
4874 const mite = miteApi ( config . get ( ) ) ;
4975 const miteTracker = tracker ( config . get ( ) ) ;
5076 const getTimeEntry = util . promisify ( mite . getTimeEntry ) ;
@@ -77,25 +103,35 @@ function main(timeEntryId, note) {
77103 promise = getTimeEntry ( timeEntryId ) ;
78104 }
79105
106+ let updateData = {
107+ ...( program . projectId && { project_id : program . projectId } ) ,
108+ ...( program . serviceId && { service_id : program . serviceId } ) ,
109+ } ;
110+
80111 return promise
81112 . then ( data => {
82113 if ( ! data ) {
83114 throw new Error ( 'Unable to find time entry with the given ID' ) ;
84115 }
85116 return data . time_entry ;
86117 } )
118+ /**
119+ * @return {Object.<string> }
120+ * @return {string } entry.note new note
121+ */
87122 . then ( timeEntry => {
88123 timeEntryId = timeEntry . id ;
89124
90- // only ask for updated note entered via editor or inquirer if it’s
91- // not been set before
92- if ( typeof note !== 'undefined' ) {
93- // use note passed over via pipe
125+ // if only service and project should be changed (no note given)
126+ if ( typeof note === 'undefined' && updateData !== { } ) {
127+ return updateData ;
128+ } else if ( typeof note !== 'undefined' ) {
129+ // note passed over via pipe or argument
94130 return { note } ;
95131 } else if ( program . editor ) {
96132 // use $EDITOR and return content
97- return openEditor ( timeEntry . note ) . then ( ( editedText ) => {
98- return { note : editedText } ;
133+ return openEditor ( timeEntry . note ) . then ( ( editorContent ) => {
134+ return { note : editorContent } ;
99135 } ) ;
100136 } else {
101137 // use interactive mode (inquirer)
0 commit comments