1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/cmd/tools/vcreate.v

74 lines
1.2 KiB
V
Raw Normal View History

2020-02-03 07:00:36 +03:00
// Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved.
2019-11-11 00:48:56 +03:00
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module main
import (
os
)
struct Create {
mut:
2020-02-13 21:27:13 +03:00
name string
2019-11-11 00:48:56 +03:00
description string
}
fn cerror(e string){
eprintln('\nerror: $e')
}
fn (c Create)write_vmod() {
2020-02-13 21:27:13 +03:00
mut vmod := os.create('${c.name}/v.mod') or {
cerror(err)
exit(1)
}
vmod_content := [
'#V Project#\n',
'Module {',
' name: \'${c.name}\',',
' description: \'${c.description}\',',
' dependencies: []',
'}'
]
2019-11-11 00:48:56 +03:00
vmod.write(vmod_content.join('\n'))
}
fn (c Create)write_main() {
2020-02-13 21:27:13 +03:00
mut main := os.create('${c.name}/${c.name}.v') or {
cerror(err)
exit(2)
}
main_content := [
'module main\n',
'fn main() {',
' println(\'Hello World !\')',
'}'
]
2019-11-11 00:48:56 +03:00
main.write(main_content.join('\n'))
}
fn main() {
mut c := Create{}
2020-02-13 21:27:13 +03:00
print('Input your project name: ')
2019-11-11 00:48:56 +03:00
c.name = os.get_line()
2020-02-13 21:27:13 +03:00
if (os.is_dir(c.name)) {
cerror('${c.name} folder already exists')
exit(3)
}
print('Input your project description: ')
2019-11-11 00:48:56 +03:00
c.description = os.get_line()
2020-02-13 21:27:13 +03:00
2019-11-11 00:48:56 +03:00
println('Initialising ...')
2020-02-13 21:27:13 +03:00
os.mkdir(c.name) or {
panic(err)
}
2019-11-11 00:48:56 +03:00
c.write_vmod()
c.write_main()
println('Complete !')
}