-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.v
70 lines (63 loc) · 1.36 KB
/
main.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
module main
import os
import cli
import log
import commands
import internal.config
const version = '0.3.1'
const default_config = 'config.toml'
// load_config loads a toml config file
fn load_config(toml_file string) !config.Config {
toml_text := os.read_file(toml_file)!
return config.load(toml_text)
}
fn init_logger() &log.Log {
mut l := log.Log{}
l.set_level(.info)
return &l
}
fn init_commands() cli.Command {
return cli.Command{
name: 'vss'
version: version
description: 'static site generator'
execute: fn (cmd cli.Command) ! {
println(cmd.help_message())
}
commands: [
cli.Command{
name: 'build'
description: 'build your site'
usage: 'vss build'
execute: fn (cmd cli.Command) ! {
mut logger := init_logger()
conf := load_config(default_config)!
mut c := commands.new_build_cmd(conf, logger)
c.run() or {
logger.error(err.msg())
println('build failed')
}
}
},
cli.Command{
name: 'serve'
description: 'serve dist'
usage: 'vss serve'
execute: fn (cmd cli.Command) ! {
mut logger := init_logger()
conf := load_config(default_config)!
mut c := commands.new_serve_cmd(conf, logger)
c.run() or {
logger.error(err.msg())
println('serve failed')
}
}
},
]
}
}
fn main() {
mut app := init_commands()
app.setup()
app.parse(os.args)
}