diff --git a/script/add-grammar b/script/add-grammar index 11bb1889..584b9cdf 100755 --- a/script/add-grammar +++ b/script/add-grammar @@ -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 +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 -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}"` diff --git a/script/licensed b/script/licensed index ea3f538f..68214d34 100755 --- a/script/licensed +++ b/script/licensed @@ -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?