-
Notifications
You must be signed in to change notification settings - Fork 0
/
vcli.v
68 lines (53 loc) · 1.59 KB
/
vcli.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
import os
import flag
import lib.restr {String}
import lib.input {str_input}
fn main() {
mut fprs := flag.new_flag_parser(os.args)
fprs.application('vcli')
fprs.version('0.1.0')
fprs.description('V CLI tool starter')
fprs.skip_executable()
mut prjname := fprs.string('name', `n`, '', "Project Name").to_lower()
version := fprs.string('version', `v`, '0.0.1', "Version")
desc := fprs.string('desc', `d`, '', "Description")
additional_args := fprs.finalize()!
if additional_args.len > 0 {
println('Unprocessed arguments:\n$additional_args.join_lines()')
}
if prjname == '' {
prjname = str_input('Please enter project name:')
if input.abort_key == prjname { return }
}
root := './$prjname'
os.mkdir(root) or {
eprintln("Failed to create project directory")
return
}
vmap := {
'prjname': prjname
'version': version
'desc': desc
}
mut text := load_template('main.v', vmap)
os.write_file('$root/${prjname}.v', text)!
text = load_template('v.mod', vmap)
os.write_file('$root/v.mod', text)!
text = load_template('.gitignore', vmap)
os.write_file('$root/.gitignore', text)!
os.execute('cp .editorconfig $root/.editorconfig')
os.execute('cp .gitattributes $root/.gitattributes')
os.execute('cp -r lib $root/')
text = '# $prjname\n$desc'
os.write_file('$root/README.md', text)!
}
fn load_template(file string, vmap map[string]string) string {
vcliroot := $env('ROOT')
mut text := os.read_file('$vcliroot/templates/$file') or {
panic('failed to read file $file')
}
for k in ['prjname', 'version', 'desc'] {
text = String(text).replace('%$k%', vmap[k])
}
return text
}