Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli, options: simplify special case handling, pass unknown flags to caller/opt.additional_args #298

Merged
merged 4 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci_emulator_run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ jobs:
vab --package-id "io.v.ci.vab.apk.deploytest" --name "V DEPLOY TEST APK" v/examples/gg/bezier.v && vab v_deploy_test_apk.apk
vab --package-id "io.v.ci.vab.aab.deploytest" --name "V DEPLOY TEST AAB" --package aab v/examples/gg/bezier.v && vab v_deploy_test_aab.aab
# Remove app in case cache is run
adb uninstall --user 0 "io.v.ci.vab.apk.deploytest"
adb uninstall --user 0 "io.v.ci.vab.aab.deploytest"
# adb uninstall --user 0 "io.v.ci.vab.apk.deploytest"
# adb uninstall --user 0 "io.v.ci.vab.aab.deploytest"

# 'flappylearning' can build but running is currently broken on Android
# Skip fireworks for now
Expand Down
23 changes: 12 additions & 11 deletions cli/options.v
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ pub fn options_from_arguments(arguments []string, defaults Options) !(Options, [
return error('`run` should only be specified once')
}

mut verbosity := defaults.verbosity
mut archs := defaults.archs.clone()
mut run_builtin_cmd := defaults.run_builtin_cmd

Expand All @@ -277,16 +276,13 @@ pub fn options_from_arguments(arguments []string, defaults Options) !(Options, [
// rip built in sub-commands at the start of the args array
run_builtin_cmd = arg
args.delete(i)
i--
} else if arg in ['-v', '--verbosity'] {
// legacy support for `vab -v` (-v *without* an integer)
verbosity_arg := args[i + 1] or { '' }
if verbosity_arg.starts_with('-') {
verbosity = 1
} else if verbosity_arg != '' {
verbosity = verbosity_arg.int()
args.delete(i + 1)
if !args[i + 1] or { '' }.is_int() {
args.insert(i + 1, '1')
i++
}
args.delete(i)
} else if arg == '--archs' {
// rip, validate and convert e.g. 'arm64-v8a, armeabi-v7a,x86' to ['arm64-v8a', 'armeabi-v7a', 'x86']
archs_value := args[i + 1] or { '' }
Expand All @@ -298,6 +294,7 @@ pub fn options_from_arguments(arguments []string, defaults Options) !(Options, [
archs = archs_value.split(',').map(it.trim_space())
args.delete(i + 1)
args.delete(i)
i--
}
}

Expand All @@ -309,8 +306,13 @@ pub fn options_from_arguments(arguments []string, defaults Options) !(Options, [
}

// Parse remaining args/flags (vab's own/native flags).
// vab used `flag.FlagParser` as flag parser so use that parsing style.
mut options, unmatched := flag.using[Options](defaults, args, style: .v_flag_parser)!
// vab has historically used `flag.FlagParser` to parse it's flags.
// All unknown/unmatched input from here is gathered in `additional_args`
// to allow the caller to decide what to do with them.
mut options, unmatched := flag.using[Options](defaults, args,
style: .v_flag_parser
mode: .relaxed
)!
options.supported_v_flags = supported_v_flags

// Here we ensure that defaults are kept as a base value and that duplicates are left out
Expand All @@ -327,7 +329,6 @@ pub fn options_from_arguments(arguments []string, defaults Options) !(Options, [
run: 'run' in cmd_args
run_builtin_cmd: run_builtin_cmd
archs: archs
verbosity: verbosity
}

$if vab_debug_options ? {
Expand Down
Loading