|
1 | | -import {Command} from 'commander'; |
| 1 | +import { Command } from 'commander'; |
2 | 2 | import Frame from './models/frame.js'; |
3 | 3 | import Config from './include/file-config.js'; |
4 | 4 | import Cli from './include/cli.js'; |
5 | 5 | import Fs from './include/filesystem.js'; |
6 | 6 |
|
7 | | - |
8 | 7 | function delCmd() { |
9 | 8 | const delCmd = new Command('delete', 'delete time record by the given id') |
10 | | - .arguments('[id]') |
11 | | - .action((id, opts, program) => { |
| 9 | + .arguments('[id]') |
| 10 | + .action((id, opts, program) => { |
12 | 11 |
|
13 | | -let config = new Config(process.cwd()); |
| 12 | + let config = new Config(process.cwd()); |
14 | 13 |
|
15 | | -if ( |
16 | | - (!id || !Fs.exists(Fs.join(config.frameDir, id + '.json'))) |
17 | | - && -Infinity === (id = Fs.newest(config.frameDir)) |
18 | | -) |
19 | | - Cli.error('No record found.'); |
| 14 | + if (!id && -Infinity === (id = Fs.newest(config.frameDir).name)) |
| 15 | + Cli.error('No record found.'); |
20 | 16 |
|
21 | | -let file = Fs.join(config.frameDir, id.replace('.json', '') + '.json'); |
22 | | -let frame = Frame.fromFile(config, file).stopMe(); |
23 | | -Fs.remove(file); |
24 | | -console.log(`Deleting record ${frame.id.magenta}`); |
25 | | -} |
26 | | -); |
27 | | -return delCmd; |
| 17 | + let file = Fs.join(config.frameDir, id.replace('.json', '') + '.json'); |
| 18 | + if (!Fs.exists(file)) { |
| 19 | + Cli.error(`Record ${id} not found.`); |
| 20 | + } else { |
| 21 | + let frame = Frame.fromFile(config, file).stopMe(); |
| 22 | + Fs.remove(file); |
| 23 | + console.log(`Deleting record ${frame.id.magenta}`); |
| 24 | + } |
| 25 | + } |
| 26 | + ); |
| 27 | + return delCmd; |
28 | 28 | } |
29 | 29 |
|
30 | 30 | export default delCmd; |
0 commit comments