mirror of
https://github.com/vlang/v.git
synced 2025-09-15 15:32:27 +03:00
flag: fix rendering bug, make newline logic/code more readable and clean (#21896)
This commit is contained in:
parent
6d4f167f48
commit
60089d61e5
2 changed files with 148 additions and 22 deletions
|
@ -70,3 +70,126 @@ fn test_attrs_override() {
|
|||
description: 'My application'
|
||||
)! == doc3
|
||||
}
|
||||
|
||||
const doc4 = 'flag_to_doc_test 1.0
|
||||
--------------------------------------------------------------------------------
|
||||
Flag to doc test.
|
||||
Content here
|
||||
|
||||
Options:
|
||||
-v, --show-version Show version and exit
|
||||
|
||||
-d, --debug <int> Debug level
|
||||
|
||||
-l <f32> Level of lorem ipsum
|
||||
and more
|
||||
many many many more.
|
||||
Notice how user newlines/format is kept since
|
||||
input lines are all less or within
|
||||
the default layout.description_padding
|
||||
and max width
|
||||
|
||||
--example <string> Looong example text without newlines or anything
|
||||
else and lorem ipsum and more and many many many
|
||||
more. Should be auto fitted
|
||||
|
||||
--square
|
||||
|
||||
-m, -mmm... (can repeat) This flag can be repeated
|
||||
|
||||
-w, --wroom <int> (allowed multiple times)
|
||||
|
||||
--the-limit <string> Looongbobbytextwithoutnewlinesoranythingelseandlorem
|
||||
ipsumandmoreandmanymanymanymore
|
||||
ffffffffffffffffffffffffffffffff f
|
||||
|
||||
-e, --extra Secret flag that does not exist on the struct,
|
||||
but we want documented (in same format as the
|
||||
others)
|
||||
|
||||
-q, --quiet-and-quite-long-flag <string>
|
||||
Mega long description and secret flag that does
|
||||
not exist on the struct, but we want documented.
|
||||
Also the flag has custom newlines and the flag
|
||||
line itself is super long
|
||||
|
||||
Footer content'
|
||||
|
||||
const doc5 = 'flag_to_doc_test 1.0
|
||||
--------------------------------------------------------------------------------
|
||||
Flag to doc test.
|
||||
Content here
|
||||
|
||||
Options:
|
||||
-v, --show-version Show version and exit
|
||||
-d, --debug <int> Debug level
|
||||
-l <f32> Level of lorem ipsum
|
||||
and more
|
||||
many many many more.
|
||||
Notice how user newlines/format is kept since
|
||||
input lines are all less or within
|
||||
the default layout.description_padding
|
||||
and max width
|
||||
--example <string> Looong example text without newlines or anything
|
||||
else and lorem ipsum and more and many many many
|
||||
more. Should be auto fitted
|
||||
--square
|
||||
-m, -mmm... (can repeat) This flag can be repeated
|
||||
-w, --wroom <int> (allowed multiple times)
|
||||
--the-limit <string> Looongbobbytextwithoutnewlinesoranythingelseandlorem
|
||||
ipsumandmoreandmanymanymanymore
|
||||
ffffffffffffffffffffffffffffffff f
|
||||
-e, --extra Secret flag that does not exist on the struct,
|
||||
but we want documented (in same format as the
|
||||
others)
|
||||
-q, --quiet-and-quite-long-flag <string>
|
||||
Mega long description and secret flag that does
|
||||
not exist on the struct, but we want documented.
|
||||
Also the flag has custom newlines and the flag
|
||||
line itself is super long
|
||||
|
||||
Footer content'
|
||||
|
||||
@[name: 'flag_to_doc_test']
|
||||
@[version: '1.0']
|
||||
struct DocTest {
|
||||
show_version bool @[short: v; xdoc: 'Show version and exit']
|
||||
debug_level int @[long: debug; short: d; xdoc: 'Debug level']
|
||||
level f32 @[only: l; xdoc: 'Override this doc string']
|
||||
example string
|
||||
square bool
|
||||
multi int @[only: m; repeats]
|
||||
wroom []int @[short: w]
|
||||
the_limit string
|
||||
}
|
||||
|
||||
const field_docs = {
|
||||
'level': 'Level of lorem ipsum\nand more\nmany many many more.\nNotice how user newlines/format is kept since\ninput lines are all less or within\nthe default layout.description_padding\nand max width'
|
||||
'example': 'Looong example text without newlines or anything else and lorem ipsum and more and many many many more. Should be auto fitted'
|
||||
'the_limit': 'Looongbobbytextwithoutnewlinesoranythingelseandlorem ipsumandmoreandmanymanymanymore ffffffffffffffffffffffffffffffff f'
|
||||
'multi': 'This flag can be repeated'
|
||||
'-e, --extra': 'Secret flag that does not exist on the struct, but we want documented (in same format as the others)'
|
||||
'-q, --quiet-and-quite-long-flag <string>': 'Mega long description and secret flag that does not exist on the struct, but we want documented. Also the flag has custom newlines\nand the flag line itself is super long'
|
||||
}
|
||||
|
||||
fn test_flag_to_doc_spacing_and_new_lines() {
|
||||
assert flag.to_doc[DocTest](
|
||||
description: 'Flag to doc test.
|
||||
Content here'
|
||||
footer: '
|
||||
Footer content'
|
||||
fields: unsafe { field_docs }
|
||||
)! == doc4
|
||||
|
||||
// Test in compact mode also
|
||||
assert flag.to_doc[DocTest](
|
||||
options: flag.DocOptions{
|
||||
compact: true
|
||||
}
|
||||
description: 'Flag to doc test.
|
||||
Content here'
|
||||
footer: '
|
||||
Footer content'
|
||||
fields: unsafe { field_docs }
|
||||
)! == doc5
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue