v doc: show a proper error message instead of panic on `v doc -m file.v`

pull/12129/head
Delyan Angelov 2021-10-09 11:56:30 +03:00
parent e267106220
commit 32ea53960e
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 9 additions and 1 deletions

View File

@ -325,6 +325,10 @@ fn (mut vd VDoc) generate_docs_from_file() {
docs << vd.docs.filter(it.head.name != 'builtin') docs << vd.docs.filter(it.head.name != 'builtin')
vd.docs = docs vd.docs = docs
} }
if dirs.len == 0 && cfg.is_multi {
eprintln('vdoc: -m requires at least 1 module folder')
exit(1)
}
vd.vprintln('Rendering docs...') vd.vprintln('Rendering docs...')
if out.path.len == 0 || out.path == 'stdout' { if out.path.len == 0 || out.path == 'stdout' {
if out.typ == .html { if out.typ == .html {
@ -332,7 +336,11 @@ fn (mut vd VDoc) generate_docs_from_file() {
} }
outputs := vd.render(out) outputs := vd.render(out)
if outputs.len == 0 { if outputs.len == 0 {
eprintln('vdoc: No documentation found for ${dirs[0]}') if dirs.len == 0 {
eprintln('vdoc: No documentation found')
} else {
eprintln('vdoc: No documentation found for ${dirs[0]}')
}
exit(1) exit(1)
} else { } else {
first := outputs.keys()[0] first := outputs.keys()[0]