Skip to content

Commit

Permalink
wip ~ ...
Browse files Browse the repository at this point in the history
  • Loading branch information
rivy committed Jan 19, 2025
1 parent 6e8eb13 commit 1a7f16e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
25 changes: 19 additions & 6 deletions cmd/v/v.v
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import v.help
import v.pref
import v.util
import v.util.version
import v.util.vflags
import v.builder
import v.builder.cbuilder

Expand Down Expand Up @@ -57,6 +58,13 @@ const external_tools = [
]
const list_of_flags_that_allow_duplicates = ['cc', 'd', 'define', 'cf', 'cflags']

fn get_raw_command_line() ?string {
$if windows {
s := C.GetCommandLine()
return if s == 0 { none } else { unsafe { string_from_wide(s) } }
} $else { return none }
}

fn main() {
mut timers_should_print := false
$if time_v ? {
Expand All @@ -75,24 +83,29 @@ fn main() {
timers.show('TOTAL')
})!
timers.start('v parsing CLI args')

println('v args=${os.args}')
// raw_command_line := $if windows { C.GetCommandLine() } $else { 'NONE' }
// eprintln('raw_command_line=${raw_command_line}')
args := os.args[1..]
raw_command_line := get_raw_command_line()
println('raw_command_line=${raw_command_line}')
raw_words := if s := raw_command_line { ?[]string(vflags.tokenize_to_args(s)) } else { ?[]string(none) }
println('raw_words=`${raw_words}`')

words := if w := raw_words { w } else { os.args }
args := words[1..]

if args.len == 0 || args[0] in ['-', 'repl'] {
if args.len == 0 {
// Running `./v` without args launches repl
if os.is_atty(0) == 0 {
mut args_and_flags := util.join_env_vflags_and_os_args()[1..].clone()
mut args_and_flags := vflags.join_env_vflags_and_args(args)[1..].clone()
args_and_flags << ['run', '-']
pref.parse_args_and_show_errors(external_tools, args_and_flags, true)
}
}
util.launch_tool(false, 'vrepl', os.args[1..])
util.launch_tool(false, 'vrepl', args)
return
}
mut args_and_flags := util.join_env_vflags_and_os_args()[1..]
mut args_and_flags := vflags.join_env_vflags_and_args(args)[1..]
prefs, command := pref.parse_args_and_show_errors(external_tools, args_and_flags,
true)
if prefs.use_cache && os.user_os() == 'windows' {
Expand Down
9 changes: 7 additions & 2 deletions vlib/v/util/vflags/vflags.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@ import strings

// join_env_vflags_and_os_args returns all the arguments (the ones from the env variable VFLAGS too), passed on the command line.
pub fn join_env_vflags_and_os_args() []string {
return join_env_vflags_and_args(os.args)
}

// join_env_vflags_and_args returns all the "command line" arguments from the environment (VOSARGS, VFLAGS) prefixed to the command line.
pub fn join_env_vflags_and_args(args_ []string) []string {
vosargs := os.getenv('VOSARGS')
if vosargs != '' {
return tokenize_to_args(vosargs)
}
vflags := os.getenv('VFLAGS')
if vflags != '' {
mut args := []string{}
args << os.args[0]
args << args_[0]
args << tokenize_to_args(vflags)
args << os.args#[1..]
args << args_#[1..]
return args
}
return os.args
Expand Down

0 comments on commit 1a7f16e

Please sign in to comment.