From cd087515fbbdda110632589d5e066e2007ac0bba Mon Sep 17 00:00:00 2001 From: StunxFS <56417208+StunxFS@users.noreply.github.com> Date: Fri, 12 Mar 2021 11:09:43 -0400 Subject: [PATCH] vcreate: use underscores instead of spaces for names (#9257) --- cmd/tools/vcreate.v | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cmd/tools/vcreate.v b/cmd/tools/vcreate.v index ec3cc155b4..d7a7ba2962 100644 --- a/cmd/tools/vcreate.v +++ b/cmd/tools/vcreate.v @@ -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)