-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstorage-sense-config.v
106 lines (100 loc) · 2.64 KB
/
storage-sense-config.v
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
module main
import cli
import omegaui.ansi.display
import omegaui.ansi.codes
import os
import watcher
import config
import manager
fn create_default_session() {
config_home := '${os.home_dir()}/.config/storage-sense'
config_file := '${os.home_dir()}/.config/storage-sense/session-config.json'
if !os.exists(config_home) || !os.exists(config_file) {
watcher.do(fn [config_home, config_file] () bool {
if !os.exists(config_home) {
os.mkdir(config_home) or {
display.println(text: 'Cannot Create config directory!', style: codes.dim)
println(err)
return false
}
}
os.create(config_file) or { return false }
os.write_file(config_file, '{}') or {
println(err)
return false
}
return true
}, 'Creating NEW Session')
}
}
fn main() {
mut app := cli.Command{
name: 'storage-sense-config'
description: 'Storage Sense Configurator version 1.0.1'
execute: fn (cmd cli.Command) ! {
create_default_session()
mut provided_options := 0
flag_checker := fn (flag cli.Flag) bool {
value := flag.get_string() or { return false }
return value != ''
}
for flag in cmd.flags {
if flag_checker(flag) {
provided_options++
if flag.name == '-add' {
manager.add(flag.get_string()!)
} else if flag.name == '-remove' {
manager.remove(flag.get_string()!)
}
}
}
if provided_options == 0 {
config_path := '${os.home_dir()}/.config/storage-sense/session-config.json'
display.println(text: 'Storage Sense Configurator v1.0.1', style: codes.bold)
display.println(
text: 'config: ${config_path}\n'
style: codes.dim
)
watcher.do(fn () bool {
configuration := config.read() or {
display.println(text: 'ERROR: Cannot Read Configuration', style: codes.bold)
return false
}
watchdogs := configuration.size()
if watchdogs == 0 {
println('There are no active watchdogs!')
return true
} else {
println('There are ${watchdogs} active watchdog(s)!')
}
display.println(
text: 'Watchdog(s) are currently listening to these files and directories:'
style: codes.dim
)
for watchdog in configuration.watchdogs {
display.println(
text: '\t- ${watchdog.path}'
style: codes.bold
fg: codes.yellow
)
}
return true
}, 'Generated Quick Overview')
}
}
flags: [
cli.Flag{
flag: .string
name: '-add'
description: 'Adds file(s) to be sensed by the storage cleaner'
},
cli.Flag{
flag: .string
name: '-remove'
description: 'Removes file(s) to be sensed by the storage cleaner'
},
]
}
app.setup()
app.parse(os.args)
}