mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v help: support v help topics
to list all help .txt file names
This commit is contained in:
parent
88a49d35e3
commit
517260a1eb
@ -54,6 +54,7 @@ V supports the following commands:
|
||||
|
||||
Use "v help <command>" 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.
|
||||
|
@ -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('')
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user