vup: support -v
parent
1bbfc271c5
commit
b6dc2d9106
|
@ -4,43 +4,51 @@ import os
|
|||
import v.pref
|
||||
import v.util
|
||||
|
||||
fn main() {
|
||||
struct App {
|
||||
is_verbose bool
|
||||
vexe string
|
||||
vroot string
|
||||
}
|
||||
|
||||
fn new_app() App {
|
||||
vexe := pref.vexe_path()
|
||||
vroot := os.dir(vexe)
|
||||
os.chdir(vroot)
|
||||
return App{
|
||||
is_verbose: '-v' in os.args
|
||||
vexe: vexe
|
||||
vroot: os.dir(vexe)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
app := new_app()
|
||||
os.chdir(app.vroot)
|
||||
println('Updating V...')
|
||||
|
||||
if !os.exists('.git') {
|
||||
// initialize as if it had been cloned
|
||||
git_command('init')
|
||||
git_command('remote add origin https://github.com/vlang/v')
|
||||
git_command('fetch')
|
||||
git_command('reset --hard origin/master')
|
||||
git_command('clean --quiet -xdf --exclude v.exe --exclude cmd/tools/vup.exe')
|
||||
app.git_command('init')
|
||||
app.git_command('remote add origin https://github.com/vlang/v')
|
||||
app.git_command('fetch')
|
||||
app.git_command('reset --hard origin/master')
|
||||
app.git_command('clean --quiet -xdf --exclude v.exe --exclude cmd/tools/vup.exe')
|
||||
} else {
|
||||
// pull latest
|
||||
git_command('pull origin master')
|
||||
app.git_command('pull origin master')
|
||||
}
|
||||
|
||||
v_hash := util.githash(false)
|
||||
current_hash := util.githash(true)
|
||||
// println(v_hash)
|
||||
// println(current_hash)
|
||||
if v_hash == current_hash {
|
||||
show_current_v_version(vexe)
|
||||
app.show_current_v_version()
|
||||
return
|
||||
}
|
||||
|
||||
$if windows {
|
||||
backup('v.exe')
|
||||
|
||||
app.backup('v.exe')
|
||||
make_result := os.exec('make.bat') or {
|
||||
panic(err)
|
||||
}
|
||||
println(make_result.output)
|
||||
|
||||
backup('cmd/tools/vup.exe')
|
||||
app.backup('cmd/tools/vup.exe')
|
||||
} $else {
|
||||
self_result := os.exec('./v self') or {
|
||||
panic(err)
|
||||
|
@ -55,19 +63,18 @@ fn main() {
|
|||
println(make_result.output)
|
||||
}
|
||||
}
|
||||
|
||||
os.exec('v cmd/tools/vup.v') or {
|
||||
panic(err)
|
||||
}
|
||||
show_current_v_version(vexe)
|
||||
app.show_current_v_version()
|
||||
}
|
||||
|
||||
fn show_current_v_version(vexe string){
|
||||
fn (app App) show_current_v_version() {
|
||||
println('Current V version:')
|
||||
os.system('$vexe version')
|
||||
os.system('$app.vexe version')
|
||||
}
|
||||
|
||||
fn backup(file string) {
|
||||
fn (app App) backup(file string) {
|
||||
backup_file := '${file}_old.exe'
|
||||
if os.exists(backup_file) {
|
||||
os.rm(backup_file)
|
||||
|
@ -75,20 +82,20 @@ fn backup(file string) {
|
|||
os.mv(file, backup_file)
|
||||
}
|
||||
|
||||
fn git_command(command string) {
|
||||
vexe := pref.vexe_path()
|
||||
vroot := os.dir(vexe)
|
||||
|
||||
fn (app App) git_command(command string) {
|
||||
git_result := os.exec('git $command') or {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if git_result.exit_code != 0 {
|
||||
if git_result.output.contains('Permission denied') {
|
||||
eprintln('have no access `$vroot`: Permission denied')
|
||||
eprintln('have no access `$app.vroot`: Permission denied')
|
||||
} else {
|
||||
eprintln(git_result.output)
|
||||
}
|
||||
exit(1)
|
||||
} else {
|
||||
if app.is_verbose {
|
||||
println(git_result.output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue