Files
linguist/script/add-grammar
2018-04-13 22:54:18 +10:00

73 lines
1.7 KiB
Ruby
Executable File

#!/usr/bin/env ruby
require "optparse"
require_relative "./helpers/all"
usage = <<-EOH
Usage:
#{$0} [-v|--verbose] [--replace grammar] url
Examples:
#{$0} https://github.com/Alhadis/language-roff
#{$0} --replace sublime-apl https://github.com/Alhadis/language-apl
EOH
$compile = false
$replace = nil
OptionParser.new do |opts|
opts.banner = usage
opts.on("-q", "--quiet", "Do not print output unless there's a failure") do
$quiet = true
end
opts.on("-rSUBMODULE", "--replace=SUBMODDULE", "Replace an existing grammar submodule.") do |name|
$replace = name
end
opts.on("-C", "--compile", "Compile grammar using the new grammar-compiler.") do
$compile = true
end
end.parse!
$url = ARGV[0]
# No URL? Print a usage message and bail.
unless $url
warn usage
exit 1
end
# Exit early if docker isn't installed or running.
log "Checking Docker is installed and running"
command('docker', 'ps')
repo_new = GrammarSource.by_url $url
Dir.chdir(ROOT)
if $replace
repo_old = GrammarSource.by_path $replace
log "Deregistering: #{repo_old.path}"
$removed = repo_old
command('git', 'submodule', 'deinit', repo_old.path)
command('git', 'rm', '-rf', repo_old.path)
command('script/grammar-compiler', 'update', '-f') if $compile
end
log "Registering new submodule: #{repo_new.path}"
command('git', 'submodule', 'add', '-f', https, repo_new)
command('script/grammar-compiler', 'add', repo_new) if $compile
log "Confirming license"
if repo_old
command('script/licensed')
else
repo_new = File.absolute_path(repo_new)
command('script/licensed', '--module', repo_new)
end
log "Updating grammar documentation in vendor/README.md"
command('bundle', 'exec', 'rake', 'samples')
command('script/sort-submodules')
command('script/list-grammars')