From 88498dfafe585d8b1a15f09761277d5fb53b9ad9 Mon Sep 17 00:00:00 2001 From: Alhadis Date: Sun, 15 Aug 2021 23:30:20 +1000 Subject: [PATCH 1/6] Split logic for adding grammars and parsing URLs --- .editorconfig | 2 +- script/add-grammar | 257 +++++++++++++++++++++++-------------------- script/normalise-url | 140 +++++++++++++++++++++++ 3 files changed, 276 insertions(+), 123 deletions(-) create mode 100755 script/normalise-url diff --git a/.editorconfig b/.editorconfig index 9a2c1b470b..9e6433f99f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -15,7 +15,7 @@ trim_trailing_whitespace = false indent_style = tab indent_size = 8 -[{Dockerfile,Makefile,*.go}] +[{Dockerfile,Makefile,*.go,script/add-grammar}] indent_style = tab indent_size = 4 diff --git a/script/add-grammar b/script/add-grammar index 75d168cb19..ef2ee45acf 100755 --- a/script/add-grammar +++ b/script/add-grammar @@ -1,124 +1,137 @@ -#!/usr/bin/env ruby - -require "optparse" -require "open3" - -ROOT = File.expand_path("../../", __FILE__) - - -# Break a repository URL into its separate components -def parse_url(input) - hosts = "github\.com|bitbucket\.org|gitlab\.com" - - # HTTPS/HTTP link pointing to recognised hosts - if input =~ /^(?:https?:\/\/)?(?:[^.@]+@)?(?:www\.)?(#{hosts})\/([^\/]+)\/([^\/]+)/i - { host: $1.downcase(), user: $2, repo: $3.sub(/\.git$/, "") } - # SSH - elsif input =~ /^git@(#{hosts}):([^\/]+)\/([^\/]+)\.git$/i - { host: $1.downcase(), user: $2, repo: $3 } - # provider:user/repo - elsif input =~ /^(github|bitbucket|gitlab):\/?([^\/]+)\/([^\/]+)\/?$/i - { host: $1.downcase(), user: $2, repo: $3 } - # user/repo - Common GitHub shorthand - elsif input =~ /^\/?([^\/]+)\/([^\/]+)\/?$/ - { host: "github.com", user: $1, repo: $2 } - else - raise "Unsupported URL: #{input}" - end -end - -# Isolate the vendor-name component of a submodule path -def parse_submodule(name) - name =~ /^(?:.*(?:vendor\/)?grammars\/)?([^\/]+)/i - path = "vendor/grammars/#{$1}" - unless File.exist?("#{ROOT}/" + path) - warn "Submodule '#{path}' does not exist. Aborting." - exit 1 - end - path -end - -# Print debugging feedback to STDOUT if not running with --quiet -def log(msg) - puts msg if $verbose -end - -def command(*args, hide_warnings: false) - log "$ #{args.join(' ')}" - stdout, stderr, status = Open3.capture3(*args) - unless status.success? - output = stdout.strip + "\n" + stderr.strip - output.each_line do |line| - log " > #{line}" - end - warn "Command failed. Aborting." - exit 1 - end - return if stderr.empty? - - unless hide_warnings - stderr.each_line do |line| - log " > #{line}" - end - end -end - -usage = """Usage: - #{$0} [-q|--quiet] [--replace grammar] url -Examples: - #{$0} https://github.com/Alhadis/language-roff - #{$0} --replace sublime-apl https://github.com/Alhadis/language-apl -""" - -$replace = nil -$verbose = true - -OptionParser.new do |opts| - opts.banner = usage - opts.on("-q", "--quiet", "Do not print output unless there's a failure") do - $verbose = false - end - opts.on("-rSUBMODULE", "--replace=SUBMODDULE", "Replace an existing grammar submodule.") do |name| - $replace = name - 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') +#!/bin/sh +set -e + +usage="${0##*/} [-q|--quiet] [--replace submodule] url" +unset replace quiet + +# Print non-essential feedback +log()([ "$quiet" ] || printf '%s\n' "$@") + +# Print an error message +warn()(printf '%s: %s\n' "${0##*/}" "$@") + +# Display a shortened help summary and bail with an error code +bad_invocation(){ + printf '%s\n' "$usage" >&2 + exit 2 +} + + +# Parse options +while [ -n "$1" ]; do case $1 in + + # Print an unabridged usage summary, then exit + -h|--help|-\?) + cat <<-HELP + Usage: + $usage + + Options: + -q, --quiet Do not print output unless there's a failure. + -r, --replace SUBMODDULE Replace an existing grammar submodule. + + Examples: + $0 https://github.com/Alhadis/language-roff + $0 --replace sublime-apl https://github.com/Alhadis/language-apl + HELP + exit ;; + + # Hide non-essential feedback + -q | --quiet) + quiet=1 + break ;; + + # Replace an existing submodule + -r* | --replace | --replace=*) + case $1 in + -r|--replace) replace=$2; shift ;; # -r [module], --replace [module] + -r*) replace=${1#??} ;; # -r[module] + --replace=*) replace=${1#*=} ;; # --replace=[module] + esac ;; + + # Double-dash: Terminate option parsing + --) + shift + break ;; + + # Invalid option: abort + --* | -?*) + warn 'invalid option: "%s"' "${0##*/}" "$1" >&2 + bad_invocation ;; + + # Argument not prefixed with a dash + *) break ;; + +esac; shift +done + + +# Don't proceed any further if we don't have a URL +[ "$1" ] || bad_invocation + + +# Check upfront that executables we depend on are available +for cmd in docker git sed ruby bundle; do + command -v "$cmd" >/dev/null 2>&1 || { + warn "Required command '$cmd' not found" + warn 'See CONTRIBUTING.md for help on getting started: https://git.io/J0eqy' + exit 1 + } +done + +# Make sure Docker's running +log 'Checking Docker is installed and running' +docker ps >/dev/null + +# Make sure we're running from checkout directory +root=`git rev-parse --git-dir` +root="${root%/.git}" +if [ ! "$root" = .git ] && [ -d "$root" ] && ! [ . -ef "$root" ] >/dev/null 2>&1; then + log "Switching directory to $root" + cd "$root" +fi # 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 - -Dir.chdir(ROOT) - -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', hide_warnings: true) -end - -log "Registering new submodule: #{repo_new}" -command('git', 'submodule', 'add', '-f', https, repo_new) -command('script/grammar-compiler', 'add', repo_new) - -log "Caching grammar license" -command("bundle", "exec", "licensed", "cache", "-c", "vendor/licenses/config.yml") - -log "Updating grammar documentation in vendor/README.md" -command('bundle', 'exec', 'rake', 'samples', hide_warnings: true) -command('script/sort-submodules') -command('script/list-grammars') +url=`script/normalise-url --protocol=https "$1"` + +# Make sure it's not already registered +path="vendor/grammars/${url##*/}" +path="${path%.git}" +if [ -e "$path" ]; then + warn "Submodule '$path' already exists. Did you forget the '--replace' option?" + warn "Run '$0 --help' for invocation advice" + exit 1 +fi + +# Remove the old submodule if we're `--replace`ing one +if [ "$replace" ]; then + + # Normalise submodule reference + replace=`printf %s "$replace" \ + | tr '[A-Z]' '[a-z]' \ + | sed 's/^\(.*\/\)\{0,1\}vendor\///; s/^grammars\///'` + replace=`git config --list \ + | grep -Fi -m1 "submodule.vendor/grammars/$replace.url=" \ + | sed 's/\.url=.*//; s/^submodule\.//' || :` + [ "$replace" ] || { + warn "Submodule '$replace' does not exist. Aborting." + exit 1 + } + + log "Deregistering submodule: $replace" + git submodule deinit "$replace" + git rm -rf "$replace" + script/grammar-compiler update -f +fi + +log "Registering new submodule: $url" +git submodule add -f "$url" "$path" +script/grammar-compiler add "$path" + +log 'Caching grammar license' +bundle exec licensed cache -c vendor/licenses/config.yml + +log 'Updating grammar documentation in vendor/README.md' +bundle exec rake samples +script/sort-submodules +script/list-grammars diff --git a/script/normalise-url b/script/normalise-url new file mode 100755 index 0000000000..80cf52fb20 --- /dev/null +++ b/script/normalise-url @@ -0,0 +1,140 @@ +#!/usr/bin/env ruby + +# Whitelisted grammar providers +HOSTS = %w[ + github.com + gitlab.com + bitbucket.org +] + +# Construct a well-formed URL from the output of `parse_url()` +def build_url(hash) + path = "#{hash[:user]}/#{hash[:repo]}.git" + if hash[:protocol] == "ssh" + "git@#{hash[:host]}:#{path}" + else + "#{hash[:protocol]}://#{hash[:host]}/#{path}" + end +end + +# Break a repository URL into its separate components +def parse_url(input) + hosts = %r[#{HOSTS.map {|x| Regexp.escape x}.join "|"}]i + + # HTTPS/HTTP link pointing to recognised hosts + if input =~ %r[^ + (?: + (? https?|ssh|git) + (?:\+(?:git|ssh))? # Allowed, but deprecated + )? :* /* + (?:[^.@]*@)? + (?:www\.)? + (? #{hosts}) /+ + (? [^:@/]+) /+ + (? [^:@/]+) + (?:\.git)? (?=$|[/#]) + ]ix; { + protocol: ($~[:protocol] or "https").downcase, + host: $~[:host].downcase, + user: $~[:user], + repo: $~[:repo] + } + + # SSH + elsif input =~ %r[^ + git (?:\+(?:ssh|https?))? @ + (?:www\.)? + (? #{hosts}) :/* + (? [^:@/]+) /+ + (? [^:@/]+) + (?:\.git)? /*$ + ]ix; { + protocol: "ssh", + host: $~[:host].downcase, + user: $~[:user], + repo: $~[:repo] + } + + # provider:user/repo + elsif input =~ %r[^ + (? + gh | github | + gl | gitlab | + bb | bitbucket + ) :/* + (? [^:@/]+) /+ + (? [^:@/]+) + (?:\.git)? /*$ + ]ix; { + protocol: "https", + host: (case $~[:host].downcase + when "gh", "github"; "github.com" + when "gl", "gitlab"; "gitlab.com" + when "bb", "bitbucket"; "bitbucket.org" + end), + user: $~[:user], + repo: $~[:repo] + } + + # user/repo - Common GitHub shorthand + elsif input =~ %r[^ + /* + (? [^:@/]+) /+ + (? [^:@/]+) + (?:\.git)? /*$ + ]ix; { + protocol: "https", + host: "github.com", + user: $~[:user], + repo: $~[:repo] + } + + # Not something we recognise + else + raise "Unsupported URL: #{input}" + end +end + + +require "optparse" +$json = false +$protocol = nil + +OptionParser.new do |opts| + opts.banner = <<~END + #{$0}: Resolve a repository URL from various formats + + Usage: + #{$0} [-p|--protocol name] ...urls + #{$0} [-j|--json] ...urls + #{$0} [-h|--hosts] + + Examples: + $ #{$0} Alhadis/language-etc BB:user/name + => https://github.com/Alhadis/language-etc.git + https://bitbucket.org/user/name.git + + Options: + END + opts.on("-h", "--hosts", "Print a list of whitelisted grammar hosts, then exit") do + puts HOSTS.join $/ + exit + end + opts.on("-j", "--json", "Output parsed URLs as an array of JSON objects") do + $json = true + end + opts.on("-pNAME", "--protocol=NAME", "Force URLs to use a protocol, even if different. Ignored for JSON output.") do |name| + $protocol = name.to_s.downcase + end +end.parse! + +if $json + require "json" + puts JSON.pretty_generate ARGV.map {|x| parse_url x}, {indent: "\t"} +else + ARGV.each do |arg| + url = parse_url arg + url[:protocol] = $protocol unless $protocol.nil? + puts build_url(url) + end +end From 0e6d487a04040e05e1e8dd2de0093d4bf480bc90 Mon Sep 17 00:00:00 2001 From: Alhadis Date: Sun, 15 Aug 2021 23:32:25 +1000 Subject: [PATCH 2/6] Make this code harder to read --- script/normalise-url | 214 +++++++++++++++++++++---------------------- 1 file changed, 107 insertions(+), 107 deletions(-) diff --git a/script/normalise-url b/script/normalise-url index 80cf52fb20..b4d0db2e04 100755 --- a/script/normalise-url +++ b/script/normalise-url @@ -2,97 +2,97 @@ # Whitelisted grammar providers HOSTS = %w[ - github.com - gitlab.com - bitbucket.org + github.com + gitlab.com + bitbucket.org ] # Construct a well-formed URL from the output of `parse_url()` def build_url(hash) - path = "#{hash[:user]}/#{hash[:repo]}.git" - if hash[:protocol] == "ssh" - "git@#{hash[:host]}:#{path}" - else - "#{hash[:protocol]}://#{hash[:host]}/#{path}" - end + path = "#{hash[:user]}/#{hash[:repo]}.git" + if hash[:protocol] == "ssh" + "git@#{hash[:host]}:#{path}" + else + "#{hash[:protocol]}://#{hash[:host]}/#{path}" + end end # Break a repository URL into its separate components def parse_url(input) - hosts = %r[#{HOSTS.map {|x| Regexp.escape x}.join "|"}]i + hosts = %r[#{HOSTS.map {|x| Regexp.escape x}.join "|"}]i - # HTTPS/HTTP link pointing to recognised hosts - if input =~ %r[^ - (?: - (? https?|ssh|git) - (?:\+(?:git|ssh))? # Allowed, but deprecated - )? :* /* - (?:[^.@]*@)? - (?:www\.)? - (? #{hosts}) /+ - (? [^:@/]+) /+ - (? [^:@/]+) - (?:\.git)? (?=$|[/#]) - ]ix; { - protocol: ($~[:protocol] or "https").downcase, - host: $~[:host].downcase, - user: $~[:user], - repo: $~[:repo] - } + # HTTPS/HTTP link pointing to recognised hosts + if input =~ %r[^ + (?: + (? https?|ssh|git) + (?:\+(?:git|ssh))? # Allowed, but deprecated + )? :* /* + (?:[^.@]*@)? + (?:www\.)? + (? #{hosts}) /+ + (? [^:@/]+) /+ + (? [^:@/]+) + (?:\.git)? (?=$|[/#]) + ]ix; { + protocol: ($~[:protocol] or "https").downcase, + host: $~[:host].downcase, + user: $~[:user], + repo: $~[:repo] + } - # SSH - elsif input =~ %r[^ - git (?:\+(?:ssh|https?))? @ - (?:www\.)? - (? #{hosts}) :/* - (? [^:@/]+) /+ - (? [^:@/]+) - (?:\.git)? /*$ - ]ix; { - protocol: "ssh", - host: $~[:host].downcase, - user: $~[:user], - repo: $~[:repo] - } + # SSH + elsif input =~ %r[^ + git (?:\+(?:ssh|https?))? @ + (?:www\.)? + (? #{hosts}) :/* + (? [^:@/]+) /+ + (? [^:@/]+) + (?:\.git)? /*$ + ]ix; { + protocol: "ssh", + host: $~[:host].downcase, + user: $~[:user], + repo: $~[:repo] + } - # provider:user/repo - elsif input =~ %r[^ - (? - gh | github | - gl | gitlab | - bb | bitbucket - ) :/* - (? [^:@/]+) /+ - (? [^:@/]+) - (?:\.git)? /*$ - ]ix; { - protocol: "https", - host: (case $~[:host].downcase - when "gh", "github"; "github.com" - when "gl", "gitlab"; "gitlab.com" - when "bb", "bitbucket"; "bitbucket.org" - end), - user: $~[:user], - repo: $~[:repo] - } + # provider:user/repo + elsif input =~ %r[^ + (? + gh | github | + gl | gitlab | + bb | bitbucket + ) :/* + (? [^:@/]+) /+ + (? [^:@/]+) + (?:\.git)? /*$ + ]ix; { + protocol: "https", + host: (case $~[:host].downcase + when "gh", "github"; "github.com" + when "gl", "gitlab"; "gitlab.com" + when "bb", "bitbucket"; "bitbucket.org" + end), + user: $~[:user], + repo: $~[:repo] + } - # user/repo - Common GitHub shorthand - elsif input =~ %r[^ - /* - (? [^:@/]+) /+ - (? [^:@/]+) - (?:\.git)? /*$ - ]ix; { - protocol: "https", - host: "github.com", - user: $~[:user], - repo: $~[:repo] - } + # user/repo - Common GitHub shorthand + elsif input =~ %r[^ + /* + (? [^:@/]+) /+ + (? [^:@/]+) + (?:\.git)? /*$ + ]ix; { + protocol: "https", + host: "github.com", + user: $~[:user], + repo: $~[:repo] + } - # Not something we recognise - else - raise "Unsupported URL: #{input}" - end + # Not something we recognise + else + raise "Unsupported URL: #{input}" + end end @@ -101,40 +101,40 @@ $json = false $protocol = nil OptionParser.new do |opts| - opts.banner = <<~END - #{$0}: Resolve a repository URL from various formats + opts.banner = <<~END + #{$0}: Resolve a repository URL from various formats - Usage: - #{$0} [-p|--protocol name] ...urls - #{$0} [-j|--json] ...urls - #{$0} [-h|--hosts] + Usage: + #{$0} [-p|--protocol name] ...urls + #{$0} [-j|--json] ...urls + #{$0} [-h|--hosts] - Examples: - $ #{$0} Alhadis/language-etc BB:user/name - => https://github.com/Alhadis/language-etc.git - https://bitbucket.org/user/name.git + Examples: + $ #{$0} Alhadis/language-etc BB:user/name + => https://github.com/Alhadis/language-etc.git + https://bitbucket.org/user/name.git - Options: - END - opts.on("-h", "--hosts", "Print a list of whitelisted grammar hosts, then exit") do - puts HOSTS.join $/ - exit - end - opts.on("-j", "--json", "Output parsed URLs as an array of JSON objects") do - $json = true - end - opts.on("-pNAME", "--protocol=NAME", "Force URLs to use a protocol, even if different. Ignored for JSON output.") do |name| - $protocol = name.to_s.downcase - end + Options: + END + opts.on("-h", "--hosts", "Print a list of whitelisted grammar hosts, then exit") do + puts HOSTS.join $/ + exit + end + opts.on("-j", "--json", "Output parsed URLs as an array of JSON objects") do + $json = true + end + opts.on("-pNAME", "--protocol=NAME", "Force URLs to use a protocol, even if different. Ignored for JSON output.") do |name| + $protocol = name.to_s.downcase + end end.parse! if $json - require "json" - puts JSON.pretty_generate ARGV.map {|x| parse_url x}, {indent: "\t"} + require "json" + puts JSON.pretty_generate ARGV.map {|x| parse_url x}, {indent: "\t"} else - ARGV.each do |arg| - url = parse_url arg - url[:protocol] = $protocol unless $protocol.nil? - puts build_url(url) - end + ARGV.each do |arg| + url = parse_url arg + url[:protocol] = $protocol unless $protocol.nil? + puts build_url(url) + end end From c9b1780f4df8284d10d869a610472b2fc2163d5f Mon Sep 17 00:00:00 2001 From: Alhadis Date: Mon, 16 Aug 2021 00:01:36 +1000 Subject: [PATCH 3/6] Fix exclusion of `.git` extension --- script/normalise-url | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/script/normalise-url b/script/normalise-url index b4d0db2e04..56ddcec44b 100755 --- a/script/normalise-url +++ b/script/normalise-url @@ -31,7 +31,7 @@ def parse_url(input) (?:www\.)? (? #{hosts}) /+ (? [^:@/]+) /+ - (? [^:@/]+) + (? [^:@/]+?) (?:\.git)? (?=$|[/#]) ]ix; { protocol: ($~[:protocol] or "https").downcase, @@ -46,7 +46,7 @@ def parse_url(input) (?:www\.)? (? #{hosts}) :/* (? [^:@/]+) /+ - (? [^:@/]+) + (? [^:@/]+?) (?:\.git)? /*$ ]ix; { protocol: "ssh", @@ -63,7 +63,7 @@ def parse_url(input) bb | bitbucket ) :/* (? [^:@/]+) /+ - (? [^:@/]+) + (? [^:@/]+?) (?:\.git)? /*$ ]ix; { protocol: "https", @@ -80,7 +80,7 @@ def parse_url(input) elsif input =~ %r[^ /* (? [^:@/]+) /+ - (? [^:@/]+) + (? [^:@/]+?) (?:\.git)? /*$ ]ix; { protocol: "https", From 9ecc2e2fa73ebc973d075cad6a9c96e9e23eea33 Mon Sep 17 00:00:00 2001 From: Alhadis Date: Wed, 1 Sep 2021 16:47:21 +1000 Subject: [PATCH 4/6] Apply changes requested in code review --- script/normalise-url | 51 +++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/script/normalise-url b/script/normalise-url index 56ddcec44b..c2d48105dc 100755 --- a/script/normalise-url +++ b/script/normalise-url @@ -1,5 +1,7 @@ #!/usr/bin/env ruby +require "English" + # Whitelisted grammar providers HOSTS = %w[ github.com @@ -19,10 +21,11 @@ end # Break a repository URL into its separate components def parse_url(input) - hosts = %r[#{HOSTS.map {|x| Regexp.escape x}.join "|"}]i + hosts = %r[#{HOSTS.map { |x| Regexp.escape x }.join "|"}]i # HTTPS/HTTP link pointing to recognised hosts - if input =~ %r[^ + case input + when %r[^ (?: (? https?|ssh|git) (?:\+(?:git|ssh))? # Allowed, but deprecated @@ -34,14 +37,14 @@ def parse_url(input) (? [^:@/]+?) (?:\.git)? (?=$|[/#]) ]ix; { - protocol: ($~[:protocol] or "https").downcase, - host: $~[:host].downcase, - user: $~[:user], - repo: $~[:repo] + protocol: ($LAST_MATCH_INFO[:protocol] or "https").downcase, + host: $LAST_MATCH_INFO[:host].downcase, + user: $LAST_MATCH_INFO[:user], + repo: $LAST_MATCH_INFO[:repo] } # SSH - elsif input =~ %r[^ + when %r[^ git (?:\+(?:ssh|https?))? @ (?:www\.)? (? #{hosts}) :/* @@ -50,13 +53,13 @@ def parse_url(input) (?:\.git)? /*$ ]ix; { protocol: "ssh", - host: $~[:host].downcase, - user: $~[:user], - repo: $~[:repo] + host: $LAST_MATCH_INFO[:host].downcase, + user: $LAST_MATCH_INFO[:user], + repo: $LAST_MATCH_INFO[:repo] } # provider:user/repo - elsif input =~ %r[^ + when %r[^ (? gh | github | gl | gitlab | @@ -67,17 +70,17 @@ def parse_url(input) (?:\.git)? /*$ ]ix; { protocol: "https", - host: (case $~[:host].downcase + host: (case $LAST_MATCH_INFO[:host].downcase when "gh", "github"; "github.com" when "gl", "gitlab"; "gitlab.com" when "bb", "bitbucket"; "bitbucket.org" end), - user: $~[:user], - repo: $~[:repo] + user: $LAST_MATCH_INFO[:user], + repo: $LAST_MATCH_INFO[:repo] } # user/repo - Common GitHub shorthand - elsif input =~ %r[^ + when %r[^ /* (? [^:@/]+) /+ (? [^:@/]+?) @@ -85,8 +88,8 @@ def parse_url(input) ]ix; { protocol: "https", host: "github.com", - user: $~[:user], - repo: $~[:repo] + user: $LAST_MATCH_INFO[:user], + repo: $LAST_MATCH_INFO[:repo] } # Not something we recognise @@ -102,22 +105,22 @@ $protocol = nil OptionParser.new do |opts| opts.banner = <<~END - #{$0}: Resolve a repository URL from various formats + #{$PROGRAM_NAME}: Resolve a repository URL from various formats Usage: - #{$0} [-p|--protocol name] ...urls - #{$0} [-j|--json] ...urls - #{$0} [-h|--hosts] + #{$PROGRAM_NAME} [-p|--protocol name] ...urls + #{$PROGRAM_NAME} [-j|--json] ...urls + #{$PROGRAM_NAME} [-h|--hosts] Examples: - $ #{$0} Alhadis/language-etc BB:user/name + $ #{$PROGRAM_NAME} Alhadis/language-etc BB:user/name => https://github.com/Alhadis/language-etc.git https://bitbucket.org/user/name.git Options: END opts.on("-h", "--hosts", "Print a list of whitelisted grammar hosts, then exit") do - puts HOSTS.join $/ + puts HOSTS.join $RS exit end opts.on("-j", "--json", "Output parsed URLs as an array of JSON objects") do @@ -130,7 +133,7 @@ end.parse! if $json require "json" - puts JSON.pretty_generate ARGV.map {|x| parse_url x}, {indent: "\t"} + puts JSON.pretty_generate ARGV.map { |x| parse_url x }, { indent: "\t" } else ARGV.each do |arg| url = parse_url arg From 507a4dc0de5385020212968ca246f002224cb17f Mon Sep 17 00:00:00 2001 From: Alhadis Date: Wed, 1 Sep 2021 23:35:34 +1000 Subject: [PATCH 5/6] Add shellcheck(1) directives --- script/add-grammar | 2 ++ 1 file changed, 2 insertions(+) diff --git a/script/add-grammar b/script/add-grammar index ef2ee45acf..98202ec1da 100755 --- a/script/add-grammar +++ b/script/add-grammar @@ -1,4 +1,5 @@ #!/bin/sh +# shellcheck disable=SC2006,SC2021 set -e usage="${0##*/} [-q|--quiet] [--replace submodule] url" @@ -86,6 +87,7 @@ docker ps >/dev/null # Make sure we're running from checkout directory root=`git rev-parse --git-dir` root="${root%/.git}" +# shellcheck disable=SC3013 if [ ! "$root" = .git ] && [ -d "$root" ] && ! [ . -ef "$root" ] >/dev/null 2>&1; then log "Switching directory to $root" cd "$root" From fb3d630ee27ffe0c707e5438b63233703f3293e1 Mon Sep 17 00:00:00 2001 From: Alhadis Date: Thu, 2 Sep 2021 21:02:31 +1000 Subject: [PATCH 6/6] Silence bundle(1) and `script/grammar-compiler` --- script/add-grammar | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script/add-grammar b/script/add-grammar index 98202ec1da..97b970aa97 100755 --- a/script/add-grammar +++ b/script/add-grammar @@ -123,7 +123,7 @@ if [ "$replace" ]; then log "Deregistering submodule: $replace" git submodule deinit "$replace" git rm -rf "$replace" - script/grammar-compiler update -f + script/grammar-compiler update -f >/dev/null 2>&1 fi log "Registering new submodule: $url" @@ -134,6 +134,6 @@ log 'Caching grammar license' bundle exec licensed cache -c vendor/licenses/config.yml log 'Updating grammar documentation in vendor/README.md' -bundle exec rake samples +bundle exec rake samples >/dev/null 2>&1 script/sort-submodules script/list-grammars