mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vcreate: optimizations and small fixes
This commit is contained in:
parent
20257d2a5c
commit
5a6f4aa61d
@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
struct Create {
|
struct Create {
|
||||||
mut:
|
mut:
|
||||||
name string
|
name string
|
||||||
description string
|
description string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,36 +19,54 @@ fn cerror(e string){
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn (c Create)write_vmod() {
|
fn (c Create)write_vmod() {
|
||||||
mut vmod := os.create('${c.name}/v.mod') or { cerror(err) exit(1) }
|
mut vmod := os.create('${c.name}/v.mod') or {
|
||||||
mut vmod_content := []string
|
cerror(err)
|
||||||
vmod_content << '#V Project#\n'
|
exit(1)
|
||||||
vmod_content << 'Module {'
|
}
|
||||||
vmod_content << ' name: \'${c.name}\','
|
vmod_content := [
|
||||||
vmod_content << ' description: \'${c.description}\','
|
'#V Project#\n',
|
||||||
vmod_content << ' dependencies: []'
|
'Module {',
|
||||||
vmod_content << '}'
|
' name: \'${c.name}\',',
|
||||||
|
' description: \'${c.description}\',',
|
||||||
|
' dependencies: []',
|
||||||
|
'}'
|
||||||
|
]
|
||||||
vmod.write(vmod_content.join('\n'))
|
vmod.write(vmod_content.join('\n'))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (c Create)write_main() {
|
fn (c Create)write_main() {
|
||||||
mut main := os.create('${c.name}/${c.name}.v') or { cerror(err) exit(2) }
|
mut main := os.create('${c.name}/${c.name}.v') or {
|
||||||
mut main_content := []string
|
cerror(err)
|
||||||
main_content << 'module main\n'
|
exit(2)
|
||||||
main_content << 'fn main() {'
|
}
|
||||||
main_content << ' println(\'Hello World !\')'
|
main_content := [
|
||||||
main_content << '}'
|
'module main\n',
|
||||||
|
'fn main() {',
|
||||||
|
' println(\'Hello World !\')',
|
||||||
|
'}'
|
||||||
|
]
|
||||||
main.write(main_content.join('\n'))
|
main.write(main_content.join('\n'))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
mut c := Create{}
|
mut c := Create{}
|
||||||
print('Choose your project name: ')
|
|
||||||
|
print('Input your project name: ')
|
||||||
c.name = os.get_line()
|
c.name = os.get_line()
|
||||||
print('Choose your project description: ')
|
|
||||||
|
if (os.is_dir(c.name)) {
|
||||||
|
cerror('${c.name} folder already exists')
|
||||||
|
exit(3)
|
||||||
|
}
|
||||||
|
|
||||||
|
print('Input your project description: ')
|
||||||
c.description = os.get_line()
|
c.description = os.get_line()
|
||||||
|
|
||||||
println('Initialising ...')
|
println('Initialising ...')
|
||||||
if (os.is_dir(c.name)) { cerror('folder already exists') exit(3) }
|
|
||||||
os.mkdir(c.name) or { panic(err) }
|
os.mkdir(c.name) or {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
c.write_vmod()
|
c.write_vmod()
|
||||||
c.write_main()
|
c.write_main()
|
||||||
println('Complete !')
|
println('Complete !')
|
||||||
|
Loading…
Reference in New Issue
Block a user