forked from larpon/shy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shy.v
85 lines (71 loc) · 1.91 KB
/
shy.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
// Copyright(C) 2022 Lars Pontoppidan. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module main
import os
import flag
import shy.cli
fn main() {
// Run any sub-commands on the spot if found in args
cli.run_subcommand(os.args) or {
eprintln(err)
exit(1)
}
// Collect user flags in an extended manner.
// Start with defaults -> merge over SHY_FLAGS -> merge over cmdline flags -> merge .shy entries.
mut opt := cli.Options{}
mut fp := &flag.FlagParser(unsafe { nil })
opt = cli.options_from_env(opt) or {
eprintln('Error while parsing `SHY_FLAGS`: ${err}')
eprintln('Use `${cli.exe_short_name} -h` to see all flags')
exit(1)
}
opt, fp = cli.args_to_options(os.args, opt) or {
eprintln('Error while parsing `os.args`: ${err}')
eprintln('Use `${cli.exe_short_name} -h` to see all flags')
exit(1)
}
if opt.dump_usage {
println(fp.usage())
exit(0)
}
// All flags after this requires an input argument
if fp.args.len == 0 {
eprintln('No arguments given')
eprintln('Use `shy -h` to see all flags')
exit(1)
}
// TODO
if opt.additional_args.len > 1 {
if opt.additional_args[0] == 'xxx' {
// xxx_arg := opt.additional_args[1]
exit(1)
}
}
// Call the doctor at this point
if opt.additional_args.len > 0 {
if opt.additional_args[0] == 'doctor' {
cli.doctor(opt)
exit(0)
}
}
input := fp.args.last()
opt.input = input
cli.validate_input(opt.input)!
opt.extend_from_dot_shy() or {
eprintln('Error while parsing `.shy`: ${err}')
eprintln('Use `${cli.exe_short_name} -h` to see all flags')
exit(1)
}
// Validate environment after options and input has been resolved
opt.validate_env() or { panic(err) }
// input_ext := os.file_ext(opt.input)
if opt.verbosity > 2 {
dump(opt)
}
// `shy /path/to/some/v/source/code`
opt.shy_v() or {
eprintln('Error while building V code: ${err}')
exit(1)
}
}