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

tools: remove cmd/tools/modules/vhelp/ & add print to v share (#17178)

This commit is contained in:
Christopher Fore 2023-02-01 04:18:23 -05:00 committed by GitHub
parent 02fc58d124
commit 2029d1830f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 12 additions and 54 deletions

View File

@ -1,41 +0,0 @@
module vhelp
import os
pub fn show_topic(topic string) {
vexe := os.real_path(os.getenv('VEXE'))
vroot := os.dir(vexe)
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)
}
println(content)
}

View File

@ -7,7 +7,7 @@ import os
import os.cmdline
import rand
import term
import vhelp
import v.help
import regex
const (
@ -43,7 +43,7 @@ fn (v1 CheckResult) + (v2 CheckResult) CheckResult {
fn main() {
if non_option_args.len == 0 || '-help' in os.args {
vhelp.show_topic('check-md')
help.print_and_exit('check-md')
exit(0)
}
if '-all' in os.args {

View File

@ -13,7 +13,7 @@ import v.fmt
import v.util
import v.util.diff
import v.parser
import vhelp
import v.help
struct FormatOptions {
is_l bool
@ -88,7 +88,7 @@ fn main() {
exit(0)
}
if files.len == 0 || '-help' in args || '--help' in args {
vhelp.show_topic('fmt')
help.print_and_exit('fmt')
exit(0)
}
mut cli_args_no_files := []string{}

View File

@ -9,7 +9,7 @@ import os.cmdline
import net.http
import net.urllib
import json
import vhelp
import v.help
import v.vmod
const (
@ -139,7 +139,7 @@ fn main() {
fn vpm_search(keywords []string) {
search_keys := keywords.map(it.replace('_', '-'))
if settings.is_help {
vhelp.show_topic('search')
help.print_and_exit('search')
exit(0)
}
if search_keys.len == 0 {
@ -355,7 +355,7 @@ fn vpm_once_filter(module_names []string) []string {
fn vpm_install(module_names []string, source Source) {
if settings.is_help {
vhelp.show_topic('install')
help.print_and_exit('install')
exit(0)
}
if module_names.len == 0 {
@ -378,7 +378,7 @@ fn vpm_install(module_names []string, source Source) {
fn vpm_update(m []string) {
mut module_names := m.clone()
if settings.is_help {
vhelp.show_topic('update')
help.print_and_exit('update')
exit(0)
}
if module_names.len == 0 {
@ -479,7 +479,7 @@ fn vpm_list() {
fn vpm_remove(module_names []string) {
if settings.is_help {
vhelp.show_topic('remove')
help.print_and_exit('remove')
exit(0)
}
if module_names.len == 0 {
@ -534,7 +534,7 @@ fn ensure_vmodules_dir_exist() {
}
fn vpm_help() {
vhelp.show_topic('vpm')
help.print_and_exit('vpm')
}
fn vcs_used_in_dir(dir string) ?[]string {

View File

@ -36,4 +36,5 @@ fn main() {
cb.copy(url)
println(url)
println('Copied URL to clipboard.')
}

View File

@ -1,8 +1,6 @@
module help
// TODO: move this file outside internal, and merge it with cmd/tools/modules/vhelp/vhelp.v .
import os
import v.pref
const (
unknown_topic = '`v help`: unknown help topic provided. Use `v help` for usage information.'
@ -10,7 +8,7 @@ const (
// print_and_exit Prints the help topic and exits
pub fn print_and_exit(topic string) {
vexe := pref.vexe_path()
vexe := @VEXE
vroot := os.dir(vexe)
topicdir := os.join_path(vroot, 'vlib', 'v', 'help')