v/cmd/v/v.v

92 lines
2.0 KiB
V
Raw Normal View History

2020-02-09 10:08:04 +01:00
// Copyright (c) 2019-2020 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 (
compiler
2020-02-16 12:50:25 +01:00
internal.help
2020-02-09 10:08:04 +01:00
os
2020-02-19 16:12:39 +01:00
v.table
v.doc
2020-02-09 10:08:04 +01:00
)
const (
2020-02-10 14:42:57 +01:00
simple_cmd = ['fmt',
2020-02-28 13:02:56 +01:00
'up', 'self',
2020-02-10 14:42:57 +01:00
'create',
'test', 'test-fmt', 'test-compiler',
'bin2v',
'repl',
2020-02-24 18:01:35 +01:00
'build-tools', 'build-examples', 'build-vbinaries',
'setup-freetype']
2020-02-09 10:08:04 +01:00
)
fn main() {
arg := join_flags_and_argument()
2020-02-10 14:42:57 +01:00
command,option := get_basic_command_and_option(arg)
2020-02-09 10:08:04 +01:00
is_verbose := '-verbose' in arg || '--verbose' in arg
if '-v' in option || '--version' in option || command == 'version' {
// Print the version and exit.
version_hash := compiler.vhash()
println('V $compiler.Version $version_hash')
return
}
if '-h' in option || '--help' in option || command == 'help' {
if is_verbose {
2020-02-16 12:50:25 +01:00
println(help.verbose_help_text)
2020-02-10 14:42:57 +01:00
}
else {
2020-02-16 12:50:25 +01:00
println(help.help_text)
2020-02-09 10:08:04 +01:00
}
return
}
if is_verbose {
eprintln('v args: $arg')
eprintln('v command: $command')
eprintln('v options: $option')
}
2020-02-19 16:12:39 +01:00
if command == 'doc' {
mod := arg[arg.len-1]
table := table.new_table()
println(doc.doc(mod, table))
return
}
2020-02-09 10:08:04 +01:00
if command in simple_cmd {
2020-02-10 14:42:57 +01:00
// External tools
2020-02-09 10:08:04 +01:00
launch_tool(is_verbose, 'v' + command, command)
return
}
if command == 'run' || command == 'build' || command.ends_with('.v') || os.exists(command) {
compile(command, arg)
return
}
match command {
'', '-' {
if arg.len == 1 {
println('Running REPL as no arguments are provided. For usage information, use `v help`.')
}
launch_tool(is_verbose, 'vrepl', '')
}
'translate' {
2020-02-19 16:12:39 +01:00
println('Translating C to V will be available in V 0.3')
2020-02-09 10:08:04 +01:00
}
'search', 'install', 'update', 'remove' {
launch_tool(is_verbose, 'vpm', command)
}
'get' {
2020-02-19 16:12:39 +01:00
println('Use `v install` to install modules from vpm.vlang.io')
2020-02-09 10:08:04 +01:00
}
'symlink' {
create_symlink()
}
2020-02-19 16:12:39 +01:00
//'doc' {
//println('Currently unimplemented')
//}
2020-02-09 10:08:04 +01:00
else {
eprintln('v $command: unknown command\nRun "v help" for usage.')
exit(1)
}
}
}