From 7caebc5781a9b6abe4932792094082e4a6b91193 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 15 May 2020 23:09:38 +0200 Subject: [PATCH] doc: print available modules --- cmd/v/v.v | 7 +++++-- vlib/v/doc/doc.v | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/cmd/v/v.v b/cmd/v/v.v index 3bb826efb7..235be139ed 100644 --- a/cmd/v/v.v +++ b/cmd/v/v.v @@ -92,12 +92,15 @@ fn main_v() { return } 'doc' { + mut mod := '' if args.len == 1 { println('v doc [module]') - exit(1) + } + else if args.len > 1 { + mod = args[1] } table := table.new_table() - println(doc.doc(args[1], table, prefs)) + println(doc.doc(mod, table, prefs)) return } else {} diff --git a/vlib/v/doc/doc.v b/vlib/v/doc/doc.v index 24cbb44e0b..03e4dc52cb 100644 --- a/vlib/v/doc/doc.v +++ b/vlib/v/doc/doc.v @@ -26,9 +26,19 @@ pub fn doc(mod string, table &table.Table, prefs &pref.Preferences) string { vlib_path := os.dir(pref.vexe_path()) + '/vlib' mod_path := mod.replace('.', os.path_separator) path := os.join_path(vlib_path, mod_path) - if !os.exists(path) { - println('module "$mod" not found') - println(path) + if mod == '' || !os.exists(path) { + if mod != '' { + println('module "$mod" not found') + } + println('\navailable modules:') + mut files := os.ls(vlib_path) or { + return '' + } + files.sort() + for file in files { + println(file) + } + // println(path) return '' } // vfiles := os.walk_ext(path, '.v')