diff --git a/cmd/v/help/default.txt b/cmd/v/help/default.txt index dfa5c12ecf..77d3b57571 100644 --- a/cmd/v/help/default.txt +++ b/cmd/v/help/default.txt @@ -54,6 +54,7 @@ V supports the following commands: Use "v help " for more information about a command, example: `v help build`, `v help build-c`, `v help build-native` Use "v help other" to see less frequently used commands. +Use "v help topics" to see a list of all known help topics. Note: Help is required to write more help topics. Only build, new, init, doc, fmt, vet, run, test, watch, search, install, remove, update, bin2v, check-md are properly documented currently. diff --git a/cmd/v/help/help.v b/cmd/v/help/help.v index 80b17bc5da..d54bf064e7 100644 --- a/cmd/v/help/help.v +++ b/cmd/v/help/help.v @@ -11,6 +11,8 @@ const ( pub fn print_and_exit(topic string) { vexe := pref.vexe_path() vroot := os.dir(vexe) + topicdir := os.join_path(vroot, 'cmd', 'v', 'help') + for b in topic { if (b >= `a` && b <= `z`) || b == `-` || (b >= `0` && b <= `9`) { continue @@ -20,11 +22,26 @@ pub fn print_and_exit(topic string) { } // `init` has the same help topic as `new` name := if topic == 'init' { 'new' } else { topic } - target_topic := os.join_path(vroot, 'cmd', 'v', 'help', '${name}.txt') + if topic == 'topics' { + println(known_topics(topicdir)) + exit(0) + } + target_topic := os.join_path(topicdir, '${name}.txt') content := os.read_file(target_topic) or { eprintln(help.unknown_topic) + eprintln(known_topics(topicdir)) exit(1) } println(content) exit(0) } + +fn known_topics(topicdir string) string { + mut res := []string{} + res << 'Known help topics:' + topic_files := os.glob(os.join_path(topicdir, '*.txt')) or { [] } + mut topics := topic_files.map(os.file_name(it).replace('.txt', '')) + topics.sort() + res << topics.join(', ') + return res.join('') +}