flag: octal format

pull/4084/head
yuyi 2020-03-21 03:21:16 +08:00 committed by GitHub
parent f89f83deb6
commit e6a679b019
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 10 deletions

View File

@ -23,7 +23,7 @@ module flag
// //
// fp.skip_executable() // fp.skip_executable()
// //
// an_int := fp.int('an_int', 666, 'some int to define 666 is default') // an_int := fp.int('an_int', 0o666, 'some int to define 0o666 is default')
// a_bool := fp.bool('a_bool', false, 'some \'real\' flag') // a_bool := fp.bool('a_bool', false, 'some \'real\' flag')
// a_float := fp.float('a_float', 1.0, 'also floats') // a_float := fp.float('a_float', 1.0, 'also floats')
// a_string := fp.string('a_string', 'no text', 'finally, some text') // a_string := fp.string('a_string', 'no text', 'finally, some text')

View File

@ -35,7 +35,7 @@ fn test_flags_could_be_defined_with_eq() {
'--a_string=stuff', '--a_string=stuff',
'--a_bool=true']) '--a_bool=true'])
assert 42 == fp.int('an_int', 0, 666, '') assert 42 == fp.int('an_int', 0, 0o666, '')
&& true == fp.bool('a_bool', 0, false, '') && true == fp.bool('a_bool', 0, false, '')
&& true == fp.bool('bool_without', 0, false, '') && true == fp.bool('bool_without', 0, false, '')
&& 2.0 == fp.float('a_float', 0, 1.0, '') && 2.0 == fp.float('a_float', 0, 1.0, '')
@ -50,7 +50,7 @@ fn test_values_could_be_defined_without_eq() {
'--a_string', 'stuff', '--a_string', 'stuff',
'--a_bool', 'true']) '--a_bool', 'true'])
assert 42 == fp.int('an_int', 0, 666, '') assert 42 == fp.int('an_int', 0, 0o666, '')
&& true == fp.bool('a_bool', 0, false, '') && true == fp.bool('a_bool', 0, false, '')
&& true == fp.bool('bool_without', 0, false, '') && true == fp.bool('bool_without', 0, false, '')
&& 2.0 == fp.float('a_float', 0, 1.0, '') && 2.0 == fp.float('a_float', 0, 1.0, '')
@ -65,7 +65,7 @@ fn test_values_could_be_defined_mixed() {
'--a_string', 'stuff', '--a_string', 'stuff',
'--a_bool=true']) '--a_bool=true'])
assert 42 == fp.int('an_int', 0, 666, '') assert 42 == fp.int('an_int', 0, 0o666, '')
&& true == fp.bool('a_bool', 0, false, '') && true == fp.bool('a_bool', 0, false, '')
&& true == fp.bool('bool_without', 0, false, '') && true == fp.bool('bool_without', 0, false, '')
&& 2.0 == fp.float('a_float', 0, 1.0, '') && 2.0 == fp.float('a_float', 0, 1.0, '')
@ -78,8 +78,8 @@ fn test_beaware_for_argument_names_with_same_prefix() {
'--shorter=7' '--shorter=7'
]) ])
assert 5 == fp.int('short', 0, 666, '') assert 5 == fp.int('short', 0, 0o666, '')
&& 7 == fp.int('shorter', 0, 666, '') && 7 == fp.int('shorter', 0, 0o666, '')
} }
fn test_beaware_for_argument_names_with_same_prefix_inverse() { fn test_beaware_for_argument_names_with_same_prefix_inverse() {
@ -88,8 +88,8 @@ fn test_beaware_for_argument_names_with_same_prefix_inverse() {
'--short', '5', '--short', '5',
]) ])
assert 5 == fp.int('short', 0, 666, '') assert 5 == fp.int('short', 0, 0o666, '')
&& 7 == fp.int('shorter', 0, 666, '') && 7 == fp.int('shorter', 0, 0o666, '')
} }
fn test_allow_to_skip_executable_path() { fn test_allow_to_skip_executable_path() {
@ -108,7 +108,7 @@ fn test_none_flag_arguments_are_allowed() {
mut fp := flag.new_flag_parser([ mut fp := flag.new_flag_parser([
'file1', '--an_int=2', 'file2', 'file3', '--bool_without', 'file4', '--outfile', 'outfile']) 'file1', '--an_int=2', 'file2', 'file3', '--bool_without', 'file4', '--outfile', 'outfile'])
assert 2 == fp.int('an_int', 0, 666, '') assert 2 == fp.int('an_int', 0, 0o666, '')
&& 'outfile' == fp.string('outfile', 0, 'bad', '') && 'outfile' == fp.string('outfile', 0, 'bad', '')
&& true == fp.bool('bool_without', 0, false, '') && true == fp.bool('bool_without', 0, false, '')
} }
@ -149,7 +149,7 @@ fn test_allow_to_build_usage_message() {
fp.version('v0.0.0') fp.version('v0.0.0')
fp.description('some short information about this tool') fp.description('some short information about this tool')
fp.int('an_int', 0, 666, 'some int to define') fp.int('an_int', 0, 0o666, 'some int to define')
fp.bool('a_bool', 0, false, 'some bool to define') fp.bool('a_bool', 0, false, 'some bool to define')
fp.bool('bool_without_but_really_big', 0, false, 'this should appear on the next line') fp.bool('bool_without_but_really_big', 0, false, 'this should appear on the next line')
fp.float('a_float', 0, 1.0, 'some float as well') fp.float('a_float', 0, 1.0, 'some float as well')