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

flag: fix parse_bool_value() (fix #22155) #22160

Merged
merged 1 commit into from
Sep 4, 2024

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Sep 4, 2024

This PR fix parse_bool_value() (fix #22155).

  • Fix parse_bool_value().
  • Add test.
import flag

pub struct Options {
pub:
	verbosity  int
	dump_usage bool
pub mut:
	additional_args []string
	archs           []string
	v_flags         []string
	api_level       string
}

fn main() {
	args := ['/my/app', '-v', '3', '-f', '-d sdl_memory_no_gc', '-f', '-d shy_use_wren', '--api',
		'21', '--archs', 'arm64-v8a', '/path/to/input.v']

	mut fp := flag.new_flag_parser(args)
	fp.application('bug')
	fp.version('0.2.0')
	fp.description('bugged')
	fp.arguments_description('not important')

	fp.skip_executable()

	mut opt := Options{
		v_flags:    fp.string_multi('flag', `f`, 'Additional flags for the V compiler')
		archs:      fp.string('archs', 0, 'arm64-v8a,armeabi-v7a,x86,x86_64', 'Comma separated string with any of archs').split(',')
		dump_usage: fp.bool('help', `h`, false, 'Show this help message and exit')
		verbosity:  fp.int_opt('verbosity', `v`, 'Verbosity level 1-3') or { 0 }
		api_level:  fp.string('api', 0, '21', 'Android API level to use (--list-apis)')
	}

	opt.additional_args = fp.finalize() or { panic(err) }

	assert opt.v_flags[0] == '-d sdl_memory_no_gc'
	assert opt.v_flags[1] == '-d shy_use_wren' // looks like the builtin support for `-h` eats the "h" in this flag
	assert opt.dump_usage == false
}

PS D:\Test\v\tt1> v run .

@larpon
Copy link
Contributor

larpon commented Sep 4, 2024

@yuyi98 thanks!

@spytheman spytheman merged commit d5c2ebc into vlang:master Sep 4, 2024
63 checks passed
@yuyi98 yuyi98 deleted the fix_flag_parse_bool branch September 5, 2024 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

flag.FlagParser bug with certain combination of flags
3 participants