alex

/

v Public
0 Issues 1 Contributor 0 Releases 4 Branches
Additions: 12 Deletions: 54 View patch
1deleted file mode 100644
2-module vhelp
3-
4-import os
5-
6-pub fn show_topic(topic string) {
7- vexe := os.real_path(os.getenv('VEXE'))
8- vroot := os.dir(vexe)
9- topicdir := os.join_path(vroot, 'vlib', 'v', 'help')
10-
11- mut path_to := topic
12- mut topics := os.walk_ext(topicdir, '.txt')
13- mut items := [][]string{}
14-
15- // Getting the directory, splitting at `/`, reversing,
16- // trimming to only indexes 0 and 1, and reversing that into the items array
17- for mut item in topics {
18- mut item_rev := item.split('/').reverse()
19- item_rev.trim(2)
20- items << item_rev.reverse()
21- }
22-
23- // Getting the path to the help topic text file
24- for cmds in items {
25- if '${topic}.txt' in cmds {
26- path_to = '${cmds[0]}/${cmds[1].replace('.txt', '')}'
27- break
28- }
29- }
30-
31- topic_dir := if topic == 'default' {
32- os.join_path(topicdir, 'default.txt')
33- } else {
34- os.join_path(topicdir, '${path_to}.txt')
35- }
36-
37- content := os.read_file(topic_dir) or {
38- eprintln('Unknown topic: ${topic}')
39- exit(1)
40- }
41- println(content)
42-}
43
1 import os.cmdline
2 import rand
3 import term
4-import vhelp
5+import v.help
6 import regex
7
8 const (
9
10 fn main() {
11 if non_option_args.len == 0 || '-help' in os.args {
12- vhelp.show_topic('check-md')
13+ help.print_and_exit('check-md')
14 exit(0)
15 }
16 if '-all' in os.args {
17
1 import v.util
2 import v.util.diff
3 import v.parser
4-import vhelp
5+import v.help
6
7 struct FormatOptions {
8 is_l bool
9 exit(0)
10 }
11 if files.len == 0 || '-help' in args || '--help' in args {
12- vhelp.show_topic('fmt')
13+ help.print_and_exit('fmt')
14 exit(0)
15 }
16 mut cli_args_no_files := []string{}
17
1 import net.http
2 import net.urllib
3 import json
4-import vhelp
5+import v.help
6 import v.vmod
7
8 const (
9 fn vpm_search(keywords []string) {
10 search_keys := keywords.map(it.replace('_', '-'))
11 if settings.is_help {
12- vhelp.show_topic('search')
13+ help.print_and_exit('search')
14 exit(0)
15 }
16 if search_keys.len == 0 {
17
18 fn vpm_install(module_names []string, source Source) {
19 if settings.is_help {
20- vhelp.show_topic('install')
21+ help.print_and_exit('install')
22 exit(0)
23 }
24 if module_names.len == 0 {
25 fn vpm_update(m []string) {
26 mut module_names := m.clone()
27 if settings.is_help {
28- vhelp.show_topic('update')
29+ help.print_and_exit('update')
30 exit(0)
31 }
32 if module_names.len == 0 {
33
34 fn vpm_remove(module_names []string) {
35 if settings.is_help {
36- vhelp.show_topic('remove')
37+ help.print_and_exit('remove')
38 exit(0)
39 }
40 if module_names.len == 0 {
41 }
42
43 fn vpm_help() {
44- vhelp.show_topic('vpm')
45+ help.print_and_exit('vpm')
46 }
47
48 fn vcs_used_in_dir(dir string) ?[]string {
49
1
2 cb.copy(url)
3 println(url)
4+ println('Copied URL to clipboard.')
5 }
6
1 module help
2
3-// TODO: move this file outside internal, and merge it with cmd/tools/modules/vhelp/vhelp.v .
4 import os
5-import v.pref
6
7 const (
8 unknown_topic = '`v help`: unknown help topic provided. Use `v help` for usage information.'
9
10 // print_and_exit Prints the help topic and exits
11 pub fn print_and_exit(topic string) {
12- vexe := pref.vexe_path()
13+ vexe := @VEXE
14 vroot := os.dir(vexe)
15 topicdir := os.join_path(vroot, 'vlib', 'v', 'help')
16