-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
61 lines (50 loc) · 1.99 KB
/
index.ts
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env node
import figlet from 'figlet'
import { Command } from 'commander';
import pomodoro from './src/lib/pomodoro';
import IPomodoroOptions from './src/types/pomodoroTypes';
const program = new Command();
let settings: IPomodoroOptions = {}
enum PomodoroStyles {
rainbow = 'rainbow',
morning = 'morning',
pastel = 'pastel',
mind = 'mind',
retro = 'retro',
}
enum PomodoroCycles {
work = 30,
coffee = 10,
break = 5,
}
console.log(figlet.textSync("Pomodor"));
program
.name('pomodor')
.description('Pomodoro timer CLI')
.version('1.0.0');
program
.option('-c, --cycle <value>', 'Inform a value to start the pomodoro, you can use the following: work, break, coffee or inform the time in minutes ex: 10', 'work')
.option('-t, --title <value>', 'Enter a title for your pomodoro', 'Initialized Pomodoro')
.option('-d, --description <value>', 'Enter a description for your pomodoro', 'Lets Go')
.option('-s, --style <value>', 'Enter a style for the pomodoro, you can use the following: rainbow ,morning, pastel, mind or retro', 'morning')
.option('-bt, --big-title', 'Show the title of the giant pomodoro')
.option('-as, --alert-sound', 'Enable sound when completing pomodoro')
.option('-nt, --notify', 'Enable system notification when completing pomodoro')
.action((newSettings) => {
let cycleValue = null
if (!Object.values(PomodoroStyles).includes(newSettings.style)) {
throw new Error('Error: Please enter a valid style => rainbow ,morning, pastel, mind or retro')
}
if (!Object.values(PomodoroCycles).includes(newSettings.cycle)) {
cycleValue = parseInt(newSettings.cycle)
if (isNaN(cycleValue))
throw new Error('Error: Please enter a valid cycle => work, coffee, break or value in minutes ex: 10')
}
settings = { ...newSettings, cycle: cycleValue ? cycleValue : PomodoroCycles[newSettings.cycle] }
})
try {
program.parse(process.argv);
pomodoro(settings.cycle, { ...settings });
} catch (err) {
console.log(err.message)
}