-
Notifications
You must be signed in to change notification settings - Fork 0
/
lsproj.ts
57 lines (47 loc) · 1.32 KB
/
lsproj.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
import {Command, flags} from '@oclif/command'
import * as fs from "fs";
import { readTasks } from "../utils/task";
import { readConfig } from "../utils/config";
import { Task } from "todo.json";
export default class ListProj extends Command {
static description = 'List projects'
static examples = [
`$ td lsproj`,
`$ td lsproj -a`
]
static flags = {
help: flags.help({char: 'h'}),
all: flags.boolean({
char: "a",
description: "list projects of all tasks including done ones"
}),
done: flags.boolean({
char: "D",
description: "list projects of only done tasks"
})
}
async run() {
const { flags } = this.parse(ListProj);
const { todoPath, donePath } = readConfig();
const projects: Set<string> = new Set();
if (!flags.done) {
let todoTasks = [] as Task[];
if (fs.existsSync(todoPath)) {
todoTasks = readTasks(todoPath);
}
todoTasks.forEach(task => {
task.projects?.forEach(p => projects.add(p));
});
}
if (flags.done || flags.all) {
let doneTasks = [] as Task[];
if (fs.existsSync(donePath)) {
doneTasks = readTasks(donePath);
}
doneTasks.forEach(task => {
task.projects?.forEach(p => projects.add(p));
});
}
this.log([...projects].join("\n"));
}
}