mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 09:40:21 +00:00
Add logic to update submodules and licenses
This commit is contained in:
@@ -37,6 +37,13 @@ def parse_submodule(name)
|
||||
path
|
||||
end
|
||||
|
||||
# Print debugging feedback to STDOUT if running with --verbose
|
||||
def log(msg)
|
||||
puts msg if $verbose
|
||||
end
|
||||
|
||||
|
||||
|
||||
usage = """Usage:
|
||||
#{$0} [--replace grammar] url
|
||||
Examples:
|
||||
@@ -44,7 +51,6 @@ Examples:
|
||||
#{$0} --replace sublime-apl https://github.com/Alhadis/language-apl
|
||||
"""
|
||||
|
||||
|
||||
$replace = nil
|
||||
$verbose = false
|
||||
|
||||
@@ -67,19 +73,21 @@ unless $url
|
||||
exit 1;
|
||||
end
|
||||
|
||||
|
||||
# Ensure the given URL is an HTTPS link
|
||||
parts = parse_url $url
|
||||
https = "https://#{parts[:host]}/#{parts[:user]}/#{parts[:repo]}"
|
||||
path = "vendor/grammars/#{parts[:repo]}"
|
||||
repl = parse_submodule($replace) if $replace
|
||||
repo_new = "vendor/grammars/#{parts[:repo]}"
|
||||
repo_old = parse_submodule($replace) if $replace
|
||||
|
||||
if $verbose
|
||||
puts "Adding grammar"
|
||||
puts "\tFrom: #{https}"
|
||||
puts "\tInto: #{path}"
|
||||
puts "\tReplacing: #{repl}" if repl
|
||||
puts "\nRegistering submodule..."
|
||||
if repo_old
|
||||
log "Deregistering: #{repo_old}"
|
||||
`git submodule deinit #{repo_old}`
|
||||
`git rm -rf #{repo_old}`
|
||||
end
|
||||
|
||||
#`git submodule add #{https} #{path}`
|
||||
log "Registering new submodule: #{repo_new}"
|
||||
`git submodule add -f #{https} #{repo_new}`
|
||||
`script/convert-grammars --add #{repo_new}`
|
||||
|
||||
log "Confirming license"
|
||||
`script/licensed --module "#{repo_new}"`
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
require "bundler/setup"
|
||||
require "licensed/cli"
|
||||
require "optparse"
|
||||
|
||||
module Licensed
|
||||
module Source
|
||||
@@ -32,7 +33,14 @@ module Licensed
|
||||
end
|
||||
end
|
||||
|
||||
source = Licensed::Source::Filesystem.new("vendor/grammars/*/", type: "grammar")
|
||||
module_path = nil
|
||||
OptionParser.new do |opts|
|
||||
opts.on("-mPATH", "--module=PATH", "Cache license file for specific grammar") do |p|
|
||||
module_path = p
|
||||
end
|
||||
end.parse!
|
||||
|
||||
source = Licensed::Source::Filesystem.new(module_path || "vendor/grammars/*/", type: "grammar")
|
||||
config = Licensed::Configuration.new
|
||||
config.sources << source
|
||||
|
||||
@@ -43,4 +51,5 @@ else
|
||||
end
|
||||
|
||||
command.run
|
||||
`git checkout -- vendor/licenses/grammar/` if module_path
|
||||
exit command.success?
|
||||
|
||||
Reference in New Issue
Block a user