Fix various syntax and logic errors

This commit is contained in:
Alhadis
2018-04-15 19:18:50 +10:00
parent f810d7fe7d
commit 573b158250

View File

@@ -43,13 +43,21 @@ def log(msg)
puts msg if $verbose
end
$aborted = false
def command(*args)
log "$ #{args.join(' ')}"
output, status = Open3.capture2e(*args)
if !status.success?
warn "Command failed. Aborting."
error.output = output.each_line { |line| " > #{line}" }
raise { output: output, status: status }
output = output.each_line { |line| " > #{line}" }
unless $aborted
$aborted = true
warn "Command failed. Aborting."
raise output
else
warn output
exit 1
end
end
end
@@ -100,29 +108,29 @@ begin
command('docker', 'ps')
# Ensure the given URL is an HTTPS link
parts = parse_url $url
https = "https://#{parts[:host]}/#{parts[:user]}/#{parts[:repo]}"
repo_new = "vendor/grammars/#{parts[:repo]}"
repo_old = parse_submodule($replace) if $replace
parts = parse_url $url
$https = "https://#{parts[:host]}/#{parts[:user]}/#{parts[:repo]}"
$repo_new = "vendor/grammars/#{parts[:repo]}"
$repo_old = parse_submodule($replace) if $replace
Dir.chdir(ROOT)
if repo_old
log "Deregistering: #{repo_old}"
command('git', 'submodule', 'deinit', repo_old)
command('git', 'rm', '-rf', repo_old)
if $repo_old
log "Deregistering: #{$repo_old}"
command('git', 'submodule', 'deinit', $repo_old)
command('git', 'rm', '-rf', $repo_old)
command('script/grammar-compiler', 'update', '-f')
end
log "Registering new submodule: #{repo_new}"
command('git', 'submodule', 'add', '-f', https, repo_new)
command('script/grammar-compiler', 'add', repo_new)
log "Registering new submodule: #{$repo_new}"
command('git', 'submodule', 'add', '-f', $https, $repo_new)
command('script/grammar-compiler', 'add', $repo_new)
log "Confirming license"
if repo_old
if $repo_old
command('script/licensed')
else
command('script/licensed', '--module', repo_new)
command('script/licensed', '--module', $repo_new)
end
log "Updating grammar documentation in vendor/README.md"
@@ -130,17 +138,21 @@ begin
command('script/sort-submodules')
command('script/list-grammars')
rescue => ex
if repo_new
`git submodule deinit #{repo_new}`
`rm -rf #{repo_new}`
`rm -rf .git/modules/#{repo_new}/`
log ex
if $repo_new
`git reset HEAD .gitmodules #{$repo_new}`
`git checkout -- vendor/licenses`
`rm -rf #{$repo_new}`
`rm -rf .git/modules/#{$repo_new}/`
restore_configs()
end
if repo_old
`rm -rf #{repo_old}`
`git submodule add -f "#{https}", "#{repo_old}"`
if $repo_old
`rm -rf #{$repo_old}`
`git submodule add -f "#{$https}", "#{$repo_old}"`
restore_configs()
end
File.write("#{ROOT}/vendor/README.md", $vendor_list)
`git reset HEAD vendor/licenses`
`git checkout -- vendor/licenses`
exit 1
end