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

vfmt fixes

This commit is contained in:
yuyi
2020-02-16 19:42:28 +08:00
committed by GitHub
parent 9eeb3dfe7e
commit e272a10bda
8 changed files with 92 additions and 33 deletions

View File

@@ -62,7 +62,7 @@ fn main() {
exit(0)
}
// we are NOT a worker at this stage, i.e. we are a parent vfmt process
possible_files := cmdline.only_non_options(cmdline.after(args, ['fmt']))
possible_files := cmdline.only_non_options(cmdline.options_after(args, ['fmt']))
if foptions.is_verbose {
eprintln('vfmt toolexe: $toolexe')
eprintln('vfmt args: ' + os.args.str())
@@ -71,11 +71,13 @@ fn main() {
}
mut files := []string
for file in possible_files {
if !os.exists(file) {
compiler.verror('"$file" does not exist.')
}
if !file.ends_with('.v') {
compiler.verror('v fmt can only be used on .v files.\nOffending file: "$file" .')
continue
}
if !os.exists(file) {
compiler.verror('"$file" does not exist.')
continue
}
files << file
}
@@ -170,7 +172,7 @@ fn (foptions &FormatOptions) format_file(file string) {
compiler_params.path = cfile
compiler_params.mod = mod_name
compiler_params.is_test = is_test_file
compiler_params.is_script = file.ends_with('.v') || file.ends_with('.vsh')
compiler_params.is_script = file.ends_with('.v') || file.ends_with('.vsh')
if foptions.is_verbose {
eprintln('vfmt format_file: file: $file')
eprintln('vfmt format_file: cfile: $cfile')

View File

@@ -478,7 +478,7 @@ fn init_settings() {
}
s.is_help = '-h' in os.args || '--help' in os.args || 'help' in os.args
s.is_verbose = '-verbose' in os.args || '--verbose' in os.args
s.server_urls = cmdline.many_values(os.args, '-server-url')
s.server_urls = cmdline.options(os.args, '-server-url')
s.vmodules_path = os.home_dir() + '.vmodules'
}

View File

@@ -77,10 +77,10 @@ pub fn run_repl(workdir string, vrepl_prefix string) []string {
version := v_version()
println(version)
println('Use Ctrl-C or `exit` to exit')
file := filepath.join( workdir, '.${vrepl_prefix}vrepl.v' )
temp_file := filepath.join( workdir, '.${vrepl_prefix}vrepl_temp.v')
mut prompt := '>>> '
temp_file := filepath.join( workdir, '.${vrepl_prefix}vrepl_temp.v')
mut prompt := '>>> '
defer {
os.rm(file)
os.rm(temp_file)
@@ -155,12 +155,12 @@ pub fn run_repl(workdir string, vrepl_prefix string) []string {
mut temp_flag := false
func_call := r.function_call(r.line)
if !(
r.line.contains(' ') ||
r.line.contains(':') ||
r.line.contains('=') ||
r.line.contains(',') ||
r.line.ends_with('++') ||
r.line.ends_with('--') ||
r.line.contains(' ') ||
r.line.contains(':') ||
r.line.contains('=') ||
r.line.contains(',') ||
r.line.ends_with('++') ||
r.line.ends_with('--') ||
r.line == '') && !func_call {
temp_line = 'println($r.line)'
temp_flag = true
@@ -219,7 +219,7 @@ fn main() {
// Support for the parameters replfolder and replprefix is needed
// so that the repl can be launched in parallel by several different
// threads by the REPL test runner.
args := cmdline.after(os.args, ['repl'])
args := cmdline.options_after(os.args, ['repl'])
replfolder := os.realpath( cmdline.option(args, '-replfolder', '.') )
replprefix := cmdline.option(args, '-replprefix', 'noprefix.')
os.chdir( replfolder )

View File

@@ -22,8 +22,8 @@ pub fn main() {
}
args_to_executable := args[1..]
args_before := cmdline.before(args_to_executable, ['test'])
args_after := cmdline.after(args_to_executable, ['test'])
args_before := cmdline.options_before(args_to_executable, ['test'])
args_after := cmdline.options_after(args_to_executable, ['test'])
if args_after.join(' ') == 'v' {
eprintln('`v test v` has been deprecated.')
@@ -53,4 +53,3 @@ pub fn main() {
exit(1)
}
}

View File

@@ -46,7 +46,7 @@ pub fn run_compiled_executable_and_exit(v &compiler.V, args []string) {
println('============ running $v.pref.out_name ============')
}
mut cmd := '"${v.pref.out_name}"'
args_after_no_options := cmdline.only_non_options( cmdline.after(args,['run','test']) )
args_after_no_options := cmdline.only_non_options( cmdline.options_after(args,['run','test']) )
if args_after_no_options.len > 1 {
cmd += ' ' + args_after_no_options[1..].join(' ')
}

View File

@@ -39,7 +39,7 @@ pub fn new_v(args []string) &compiler.V {
mut out_name := cmdline.option(args, '-o', '')
mut dir := args.last()
if 'run' in args {
args_after_run := cmdline.only_non_options( cmdline.after(args,['run']) )
args_after_run := cmdline.only_non_options( cmdline.options_after(args,['run']) )
dir = if args_after_run.len>0 { args_after_run[0] } else { '' }
}
if dir == 'v.v' {
@@ -95,9 +95,8 @@ pub fn new_v(args []string) &compiler.V {
}
// println('VROOT=$vroot')
cflags := cmdline.many_values(args, '-cflags').join(' ')
defines := cmdline.many_values(args, '-d')
cflags := cmdline.options(args, '-cflags').join(' ')
defines := cmdline.options(args, '-d')
compile_defines, compile_defines_all := parse_defines( defines )
rdir := os.realpath(dir)
@@ -194,7 +193,7 @@ pub fn new_v(args []string) &compiler.V {
}
fn find_c_compiler_thirdparty_options(args []string) string {
mut cflags := cmdline.many_values(args,'-cflags')
mut cflags := cmdline.options(args, '-cflags')
$if !windows {
cflags << '-fPIC'
}
@@ -226,4 +225,3 @@ fn parse_defines(defines []string) ([]string,[]string) {
}
return compile_defines, compile_defines_all
}