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

vcreate: use underscores instead of spaces for names (#9257)

This commit is contained in:
StunxFS 2021-03-12 11:09:43 -04:00 committed by GitHub
parent 9db8a61b92
commit cd087515fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,6 +21,15 @@ fn cerror(e string) {
eprintln('\nerror: $e')
}
fn check_name(name string) string {
if name.contains(' ') {
cname := name.replace(' ', '_')
eprintln('warning: the project name cannot contain spaces, the name will be changed to `$cname`')
return cname
}
return name
}
fn vmod_content(c Create) string {
return [
'Module {',
@ -99,7 +108,7 @@ fn (c &Create) create_git_repo(dir string) {
fn create(args []string) {
mut c := Create{}
c.name = if args.len > 0 { args[0] } else { os.input('Input your project name: ') }
c.name = check_name(if args.len > 0 { args[0] } else { os.input('Input your project name: ') })
if c.name == '' {
cerror('project name cannot be empty')
exit(1)
@ -136,7 +145,7 @@ fn init_project() {
exit(3)
}
mut c := Create{}
c.name = os.file_name(os.getwd())
c.name = check_name(os.file_name(os.getwd()))
c.description = ''
c.write_vmod(false)
c.write_main(false)