mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v: support VFLAGS, fix 'v run source.v arg after source'
This commit is contained in:
parent
75c6545857
commit
95709811e0
@ -48,7 +48,7 @@ fn main() {
|
||||
//}
|
||||
toolexe := os.executable()
|
||||
util.set_vroot_folder(os.dir(os.dir(os.dir(toolexe))))
|
||||
args := join_flags_and_argument()
|
||||
args := util.join_env_vflags_and_os_args()
|
||||
foptions := FormatOptions{
|
||||
is_c: '-c' in args
|
||||
is_l: '-l' in args
|
||||
@ -326,31 +326,6 @@ fn get_compile_name_of_potential_v_project(file string) string {
|
||||
return pfolder
|
||||
}
|
||||
|
||||
//TODO Move join_flags_and_argument() and non_empty() into `cmd/internal` when v.mod work correctly
|
||||
//to prevent code duplication with `cmd/v` (cmd/v/flag.v)
|
||||
fn join_flags_and_argument() []string {
|
||||
vosargs := os.getenv('VOSARGS')
|
||||
if vosargs != '' {
|
||||
return non_empty(vosargs.split(' '))
|
||||
}
|
||||
|
||||
mut args := []string
|
||||
vflags := os.getenv('VFLAGS')
|
||||
if vflags != '' {
|
||||
args << os.args[0]
|
||||
args << vflags.split(' ')
|
||||
if os.args.len > 1 {
|
||||
args << os.args[1..]
|
||||
}
|
||||
return non_empty(args)
|
||||
}
|
||||
|
||||
return non_empty(os.args)
|
||||
}
|
||||
fn non_empty(arg []string) []string {
|
||||
return arg.filter(it != '')
|
||||
}
|
||||
|
||||
fn verror(s string){
|
||||
util.verror('vfmt error', s)
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ const (
|
||||
)
|
||||
|
||||
fn main() {
|
||||
args := os.args[1..]
|
||||
args := util.join_env_vflags_and_os_args()[1..]
|
||||
//args = 123
|
||||
if args.len == 0 || args[0] in ['-', 'repl'] {
|
||||
// Running `./v` without args launches repl
|
||||
@ -182,7 +182,8 @@ fn parse_args(args []string) (&pref.Preferences, string) {
|
||||
else if command == 'run' {
|
||||
res.is_run = true
|
||||
res.path = args[command_pos+1]
|
||||
res.run_args = args[command_pos+1..]
|
||||
res.run_args = if command_pos+1 < args.len { args[command_pos+2..] } else { []string }
|
||||
eprintln('res.run_args: ' + res.run_args.join(' '))
|
||||
}
|
||||
if command == 'build-module' {
|
||||
res.build_mode = .build_module
|
||||
|
@ -220,3 +220,25 @@ fn replace_op(s string) string {
|
||||
}
|
||||
return s[..s.len - 1] + suffix
|
||||
}
|
||||
|
||||
pub fn join_env_vflags_and_os_args() []string {
|
||||
vosargs := os.getenv('VOSARGS')
|
||||
if vosargs != '' {
|
||||
return non_empty(vosargs.split(' '))
|
||||
}
|
||||
mut args := []string
|
||||
vflags := os.getenv('VFLAGS')
|
||||
if vflags != '' {
|
||||
args << os.args[0]
|
||||
args << vflags.split(' ')
|
||||
if os.args.len > 1 {
|
||||
args << os.args[1..]
|
||||
}
|
||||
return non_empty(args)
|
||||
}
|
||||
return non_empty(os.args)
|
||||
}
|
||||
|
||||
fn non_empty(arg []string) []string {
|
||||
return arg.filter(it != '')
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user