/
v.v
141 lines (137 loc) · 3.42 KB
/
v.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright (c) 2019-2021 Alexander Medvednikov. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module main
import help
import os
import v.pref
import v.util
import v.builder
const (
external_tools = [
'bin2v',
'bug',
'build-examples',
'build-tools',
'build-vbinaries',
'check-md',
'complete',
'doc',
'doctor',
'fmt',
'repl',
'self',
'setup-freetype',
'symlink',
'test',
'test-all', /* runs most of the tests and other checking tools, that will be run by the CI */
'test-cleancode',
'test-fmt',
'test-parser',
'test-self',
'tracev',
'up',
'vet',
'wipe-cache',
'watch',
]
list_of_flags_that_allow_duplicates = ['cc', 'd', 'define', 'cf', 'cflags']
)
fn main() {
mut timers_should_print := false
$if time_v ? {
timers_should_print = true
}
mut timers := util.new_timers(timers_should_print)
timers.start('v total')
defer {
timers.show('v total')
}
timers.start('v start')
timers.show('v start')
args := os.args[1..]
// args = 123
if args.len == 0 || args[0] in ['-', 'repl'] {
// Running `./v` without args launches repl
if args.len == 0 {
if os.is_atty(0) != 0 {
println('Welcome to the V REPL (for help with V itself, type `exit`, then run `v help`).')
} else {
mut args_and_flags := util.join_env_vflags_and_os_args()[1..].clone()
args_and_flags << ['run', '-']
pref.parse_args(external_tools, args_and_flags)
}
}
util.launch_tool(false, 'vrepl', os.args[1..])
return
}
args_and_flags := util.join_env_vflags_and_os_args()[1..]
prefs, command := pref.parse_args(external_tools, args_and_flags)
if prefs.is_verbose {
// println('args= ')
// println(args) // QTODO
// println('prefs= ')
// println(prefs) // QTODO
}
if prefs.use_cache && os.user_os() == 'windows' {
eprintln('-usecache is currently disabled on windows')
exit(1)
}
// Start calling the correct functions/external tools
// Note for future contributors: Please add new subcommands in the `match` block below.
if command in external_tools {
// External tools
util.launch_tool(prefs.is_verbose, 'v' + command, os.args[1..])
return
}
match command {
'help' {
invoke_help_and_exit(args)
}
'new', 'init' {
util.launch_tool(prefs.is_verbose, 'vcreate', os.args[1..])
return
}
'translate' {
eprintln('Translating C to V will be available in V 0.3')
exit(1)
}
'install', 'list', 'outdated', 'remove', 'search', 'show', 'update', 'upgrade' {
util.launch_tool(prefs.is_verbose, 'vpm', os.args[1..])
return
}
'vlib-docs' {
util.launch_tool(prefs.is_verbose, 'vdoc', ['doc', 'vlib'])
}
'get' {
eprintln('V Error: Use `v install` to install modules from vpm.vlang.io')
exit(1)
}
'version' {
println(util.full_v_version(prefs.is_verbose))
return
}
else {}
}
if command in ['run', 'build', 'build-module'] || command.ends_with('.v') || os.exists(command) {
// println('command')
// println(prefs.path)
builder.compile(command, prefs)
return
}
if prefs.is_help {
invoke_help_and_exit(args)
}
eprintln('v $command: unknown command\nRun "v help" for usage.')
exit(1)
}
fn invoke_help_and_exit(remaining []string) {
match remaining.len {
0, 1 { help.print_and_exit('default') }
2 { help.print_and_exit(remaining[1]) }
else {}
}
println('`v help`: provide only one help topic.')
println('For usage information, use `v help`.')
exit(1)
}