mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
tools: bugfixes and new features for oldv and performance_compare
This commit is contained in:

committed by
Alexander Medvednikov

parent
0d93eeb3fe
commit
c1cc203c17
@ -54,6 +54,23 @@ pub struct Flag {
|
||||
// and also the default value, when the flag is not given
|
||||
}
|
||||
|
||||
pub fn (f Flag) str() string {
|
||||
return ''
|
||||
+' flag:\n'
|
||||
+' name: $f.name\n'
|
||||
+' abbr: $f.abbr\n'
|
||||
+' usag: $f.usage\n'
|
||||
+' desc: $f.val_desc'
|
||||
}
|
||||
pub fn (af []Flag) str() string {
|
||||
mut res := []string
|
||||
res << '\n []Flag = ['
|
||||
for f in af {
|
||||
res << f.str()
|
||||
}
|
||||
res << ' ]'
|
||||
return res.join('\n')
|
||||
}
|
||||
//
|
||||
pub struct FlagParser {
|
||||
pub mut:
|
||||
@ -135,7 +152,10 @@ fn (fs mut FlagParser) parse_value(longhand string, shorthand byte) []string {
|
||||
//End of input. We're done here.
|
||||
break
|
||||
}
|
||||
if arg == full || (arg[0] == `-` && arg[1] == shorthand && arg.len == 2) {
|
||||
if arg[0] != `-` {
|
||||
continue
|
||||
}
|
||||
if (arg.len == 2 && arg[0] == `-` && arg[1] == shorthand ) || arg == full {
|
||||
if i+1 > fs.args.len {
|
||||
panic("Missing argument for '$longhand'")
|
||||
}
|
||||
@ -177,7 +197,13 @@ fn (fs mut FlagParser) parse_bool_value(longhand string, shorthand byte) ?string
|
||||
//End of input. We're done.
|
||||
break
|
||||
}
|
||||
if arg == full || (arg[0] == `-` && arg[1] == shorthand && arg.len == 2) {
|
||||
if arg.len == 0 {
|
||||
continue
|
||||
}
|
||||
if arg[0] != `-` {
|
||||
continue
|
||||
}
|
||||
if ( arg.len == 2 && arg[0] == `-` && arg[1] == shorthand ) || arg == full {
|
||||
if fs.args.len > i+1 && (fs.args[i+1] in ['true', 'false']) {
|
||||
val := fs.args[i+1]
|
||||
fs.args.delete(i+1)
|
||||
@ -194,7 +220,7 @@ fn (fs mut FlagParser) parse_bool_value(longhand string, shorthand byte) ?string
|
||||
fs.args.delete(i)
|
||||
return val
|
||||
}
|
||||
if arg[0] == `-` && arg.index_byte(shorthand) != -1 {
|
||||
if arg[0] == `-` && arg[1] != `-` && arg.index_byte(shorthand) != -1 {
|
||||
// -abc is equivalent to -a -b -c
|
||||
return 'true'
|
||||
}
|
||||
|
@ -320,3 +320,24 @@ fn test_multiple_arguments() {
|
||||
assert b[0] == 'a' && b[1] == 'c' && b[2] == 'b'
|
||||
assert c[0] == 1.23 && c[1] == 2.34 && c[2] == 3.45
|
||||
}
|
||||
|
||||
fn test_long_options_that_start_with_the_same_letter_as_another_short_option() {
|
||||
mut fp := flag.new_flag_parser([
|
||||
'--vabc', '/abc',
|
||||
])
|
||||
verbose := fp.bool_('verbose', `v`, false, 'Be more verbose.')
|
||||
vabc := fp.string_('vabc', `x`, 'default', 'Another option that *may* conflict with v, but *should not*')
|
||||
assert verbose == false
|
||||
assert vabc == '/abc'
|
||||
}
|
||||
|
||||
fn test_long_options_that_start_with_the_same_letter_as_another_short_option_both_set() {
|
||||
mut fp := flag.new_flag_parser([
|
||||
'-v',
|
||||
'--vabc', '/abc',
|
||||
])
|
||||
verbose := fp.bool_('verbose', `v`, false, 'Be more verbose.')
|
||||
vabc := fp.string_('vabc', `x`, 'default', 'Another option that *may* conflict with v, but *should not*')
|
||||
assert verbose == true
|
||||
assert vabc == '/abc'
|
||||
}
|
||||
|
Reference in New Issue
Block a user