mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
2c424c1aa6
commit
dcbb196e21
@ -12,7 +12,6 @@ struct Create {
|
|||||||
mut:
|
mut:
|
||||||
name string
|
name string
|
||||||
description string
|
description string
|
||||||
version string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cerror(e string){
|
fn cerror(e string){
|
||||||
@ -26,7 +25,6 @@ fn (c Create)write_vmod() {
|
|||||||
vmod_content << 'Module {'
|
vmod_content << 'Module {'
|
||||||
vmod_content << ' name: \'${c.name}\','
|
vmod_content << ' name: \'${c.name}\','
|
||||||
vmod_content << ' description: \'${c.description}\','
|
vmod_content << ' description: \'${c.description}\','
|
||||||
vmod_content << ' version: v${c.version},'
|
|
||||||
vmod_content << ' dependencies: []'
|
vmod_content << ' dependencies: []'
|
||||||
vmod_content << '}'
|
vmod_content << '}'
|
||||||
vmod.write(vmod_content.join('\n'))
|
vmod.write(vmod_content.join('\n'))
|
||||||
@ -36,36 +34,22 @@ 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 { cerror(err) exit(2) }
|
||||||
mut main_content := []string
|
mut main_content := []string
|
||||||
main_content << 'module main\n'
|
main_content << 'module main\n'
|
||||||
main_content << 'import ( mod )\n'
|
|
||||||
main_content << 'fn main() {'
|
main_content << 'fn main() {'
|
||||||
main_content << ' println(\'Hello World !\')'
|
main_content << ' println(\'Hello World !\')'
|
||||||
main_content << '}'
|
main_content << '}'
|
||||||
main.write(main_content.join('\n'))
|
main.write(main_content.join('\n'))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (_ Create)write_mod(){
|
|
||||||
os.mkdir('${c.name}/mod')
|
|
||||||
mod := os.create('${c.name}/mod/mod.v') or {return}
|
|
||||||
mut mod_in := []string
|
|
||||||
mod_in << 'module mod\n'
|
|
||||||
mod_in << 'pub fn add(i, j int) int {'
|
|
||||||
mod_in << ' return i + j'
|
|
||||||
mod_in << '}\n'
|
|
||||||
mod.write(mod_in.join('\n'))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
mut c := Create{}
|
mut c := Create{}
|
||||||
print('Choose your project name: ')
|
print('Choose your project name: ')
|
||||||
c.name = os.get_line()
|
c.name = os.get_line()
|
||||||
print('Choose your project description: ')
|
print('Choose your project description: ')
|
||||||
c.description = os.get_line()
|
c.description = os.get_line()
|
||||||
c.version='0.0.1'
|
|
||||||
println('Initialising ...')
|
println('Initialising ...')
|
||||||
if (os.is_dir(c.name)) { cerror('folder already exists') exit(3) }
|
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()
|
||||||
c.write_mod() // add a user defined module
|
|
||||||
println('Complete !')
|
println('Complete !')
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user