1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

v.help: reorganise the folder layout of the v help topic text files (#17155)

This commit is contained in:
Christopher Fore
2023-01-31 05:04:01 -05:00
committed by GitHub
parent d563739264
commit b3d742d13a
77 changed files with 1104 additions and 830 deletions

View File

@ -5,8 +5,35 @@ import os
pub fn show_topic(topic string) {
vexe := os.real_path(os.getenv('VEXE'))
vroot := os.dir(vexe)
target_topic := os.join_path(vroot, 'vlib', 'v', 'help', '${topic}.txt')
content := os.read_file(target_topic) or {
topicdir := os.join_path(vroot, 'vlib', 'v', 'help')
mut path_to := topic
mut topics := os.walk_ext(topicdir, '.txt')
mut items := [][]string{}
// Getting the directory, splitting at `/`, reversing,
// trimming to only indexes 0 and 1, and reversing that into the items array
for mut item in topics {
mut item_rev := item.split('/').reverse()
item_rev.trim(2)
items << item_rev.reverse()
}
// Getting the path to the help topic text file
for cmds in items {
if '${topic}.txt' in cmds {
path_to = '${cmds[0]}/${cmds[1].replace('.txt', '')}'
break
}
}
topic_dir := if topic == 'default' {
os.join_path(topicdir, 'default.txt')
} else {
os.join_path(topicdir, '${path_to}.txt')
}
content := os.read_file(topic_dir) or {
eprintln('Unknown topic: ${topic}')
exit(1)
}