cli: create project helper
parent
703202cc08
commit
76c27c0b03
|
@ -16,6 +16,8 @@
|
||||||
/tools/vup.exe
|
/tools/vup.exe
|
||||||
/tools/vpm
|
/tools/vpm
|
||||||
/tools/vpm.exe
|
/tools/vpm.exe
|
||||||
|
/tools/vcreate
|
||||||
|
/tools/vcreate.exe
|
||||||
*.exe
|
*.exe
|
||||||
*.o
|
*.o
|
||||||
.*.c
|
.*.c
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
// Copyright (c) 2019 Alexander Medvednikov. 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
|
||||||
|
)
|
||||||
|
|
||||||
|
struct Create {
|
||||||
|
mut:
|
||||||
|
name string
|
||||||
|
description string
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cerror(e string){
|
||||||
|
eprintln('\nerror: $e')
|
||||||
|
}
|
||||||
|
|
||||||
|
fn (c Create)write_vmod() {
|
||||||
|
vmod := os.create('${c.name}/v.mod') or { cerror(err) exit(1) }
|
||||||
|
mut vmod_content := []string
|
||||||
|
vmod_content << '#V Project#\n'
|
||||||
|
vmod_content << 'Module {'
|
||||||
|
vmod_content << ' name: \'${c.name}\','
|
||||||
|
vmod_content << ' description: \'${c.description}\','
|
||||||
|
vmod_content << ' dependencies: []'
|
||||||
|
vmod_content << '}'
|
||||||
|
vmod.write(vmod_content.join('\n'))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn (c Create)write_main() {
|
||||||
|
main := os.create('${c.name}/${c.name}.v') or { cerror(err) exit(2) }
|
||||||
|
mut main_content := []string
|
||||||
|
main_content << 'module main\n'
|
||||||
|
main_content << 'fn main() {'
|
||||||
|
main_content << ' println(\'Hello World !\')'
|
||||||
|
main_content << '}'
|
||||||
|
main.write(main_content.join('\n'))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
mut c := Create{}
|
||||||
|
print('Choose your project name: ')
|
||||||
|
c.name = os.get_line()
|
||||||
|
print('Choose your project description: ')
|
||||||
|
c.description = os.get_line()
|
||||||
|
println('Initialising ...')
|
||||||
|
if (os.is_dir(c.name)) { cerror('folder already exists') exit(3) }
|
||||||
|
os.mkdir(c.name)
|
||||||
|
c.write_vmod()
|
||||||
|
c.write_main()
|
||||||
|
println('Complete !')
|
||||||
|
}
|
4
v.v
4
v.v
|
@ -55,6 +55,10 @@ fn main() {
|
||||||
compiler.create_symlink()
|
compiler.create_symlink()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
else if 'create' in commands {
|
||||||
|
compiler.launch_tool('vcreate')
|
||||||
|
return
|
||||||
|
}
|
||||||
// TODO quit if the v compiler is too old
|
// TODO quit if the v compiler is too old
|
||||||
// u := os.file_last_mod_unix('v')
|
// u := os.file_last_mod_unix('v')
|
||||||
// If there's no tmp path with current version yet, the user must be using a pre-built package
|
// If there's no tmp path with current version yet, the user must be using a pre-built package
|
||||||
|
|
|
@ -71,6 +71,7 @@ Commands:
|
||||||
fmt Run vfmt to format the source code. [wip]
|
fmt Run vfmt to format the source code. [wip]
|
||||||
doc Run vdoc over the source code and produce documentation.
|
doc Run vdoc over the source code and produce documentation.
|
||||||
translate Translates C to V. [wip, will be available in V 0.3]
|
translate Translates C to V. [wip, will be available in V 0.3]
|
||||||
|
create Create a new v project interactively. Answer the questions, and run it with `v run projectname`
|
||||||
|
|
||||||
V package management commands:
|
V package management commands:
|
||||||
search keywords Search the https://vpm.vlang.io/ module repository for matching modules and shows their details.
|
search keywords Search the https://vpm.vlang.io/ module repository for matching modules and shows their details.
|
||||||
|
|
Loading…
Reference in New Issue