forked from kriskbx/gitlab-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgtt-delete.js
More file actions
executable file
·30 lines (25 loc) · 991 Bytes
/
gtt-delete.js
File metadata and controls
executable file
·30 lines (25 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { Command } from 'commander';
import Frame from './models/frame.js';
import Config from './include/file-config.js';
import Cli from './include/cli.js';
import Fs from './include/filesystem.js';
function delCmd() {
const delCmd = new Command('delete', 'delete time record by the given id')
.arguments('[id]')
.action((id, opts, program) => {
let config = new Config(process.cwd());
if (!id && -Infinity === (id = Fs.newest(config.frameDir).name))
Cli.error('No record found.');
let file = Fs.join(config.frameDir, id.replace('.json', '') + '.json');
if (!Fs.exists(file)) {
Cli.error(`Record ${id} not found.`);
} else {
let frame = Frame.fromFile(config, file).stopMe();
Fs.remove(file);
console.log(`Deleting record ${frame.id.magenta}`);
}
}
);
return delCmd;
}
export default delCmd;