mirror of
				https://github.com/KevinMidboe/linguist.git
				synced 2025-10-29 17:50:22 +00:00 
			
		
		
		
	Flatten whitespace
This commit is contained in:
		| @@ -7,43 +7,42 @@ ROOT = File.expand_path("../../", __FILE__) | |||||||
|  |  | ||||||
| # Break a repository URL into its separate components | # Break a repository URL into its separate components | ||||||
| def parse_url(input) | def parse_url(input) | ||||||
| 	hosts = "github\.com|bitbucket\.org|gitlab\.com" |   hosts = "github\.com|bitbucket\.org|gitlab\.com" | ||||||
|    |    | ||||||
| 	# HTTPS/HTTP link pointing to recognised hosts |   # HTTPS/HTTP link pointing to recognised hosts | ||||||
| 	if input =~ /^(?:https?:\/\/)?(?:[^.@]+@)?(?:www\.)?(#{hosts})\/([^\/]+)\/([^\/]+)/i |   if input =~ /^(?:https?:\/\/)?(?:[^.@]+@)?(?:www\.)?(#{hosts})\/([^\/]+)\/([^\/]+)/i | ||||||
| 		{ host: $1.downcase(), user: $2, repo: $3.sub(/\.git$/, "") } |     { host: $1.downcase(), user: $2, repo: $3.sub(/\.git$/, "") } | ||||||
| 	# SSH |   # SSH | ||||||
| 	elsif input =~ /^git@(#{hosts}):([^\/]+)\/([^\/]+)\.git$/i |   elsif input =~ /^git@(#{hosts}):([^\/]+)\/([^\/]+)\.git$/i | ||||||
| 		{ host: $1.downcase(), user: $2, repo: $3 } |     { host: $1.downcase(), user: $2, repo: $3 } | ||||||
| 	# provider:user/repo |   # provider:user/repo | ||||||
| 	elsif input =~ /^(github|bitbucket|gitlab):\/?([^\/]+)\/([^\/]+)\/?$/i |   elsif input =~ /^(github|bitbucket|gitlab):\/?([^\/]+)\/([^\/]+)\/?$/i | ||||||
| 		{ host: $1.downcase(), user: $2, repo: $3 } |     { host: $1.downcase(), user: $2, repo: $3 } | ||||||
| 	# user/repo - Common GitHub shorthand |   # user/repo - Common GitHub shorthand | ||||||
| 	elsif input =~ /^\/?([^\/]+)\/([^\/]+)\/?$/ |   elsif input =~ /^\/?([^\/]+)\/([^\/]+)\/?$/ | ||||||
| 		{ host: "github.com", user: $1, repo: $2 } |     { host: "github.com", user: $1, repo: $2 } | ||||||
| 	else |   else | ||||||
| 		raise "Unsupported URL: #{input}" |     raise "Unsupported URL: #{input}" | ||||||
| 	end |   end | ||||||
| end | end | ||||||
|  |  | ||||||
| # Isolate the vendor-name component of a submodule path | # Isolate the vendor-name component of a submodule path | ||||||
| def parse_submodule(name) | def parse_submodule(name) | ||||||
| 	name =~ /^(?:.*(?:vendor\/)?grammars\/)?([^\/]+)/i |   name =~ /^(?:.*(?:vendor\/)?grammars\/)?([^\/]+)/i | ||||||
| 	path = "vendor/grammars/#{$1}" |   path = "vendor/grammars/#{$1}" | ||||||
| 	unless File.exist?("#{ROOT}/" + path) |   unless File.exist?("#{ROOT}/" + path) | ||||||
| 		warn "Submodule '#{path}' does not exist. Aborting." |     warn "Submodule '#{path}' does not exist. Aborting." | ||||||
| 		exit 1 |     exit 1 | ||||||
| 	end |   end | ||||||
| 	path |   path | ||||||
| end | end | ||||||
|  |  | ||||||
| # Print debugging feedback to STDOUT if running with --verbose | # Print debugging feedback to STDOUT if running with --verbose | ||||||
| def log(msg) | def log(msg) | ||||||
| 	puts msg if $verbose |   puts msg if $verbose | ||||||
| end | end | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| usage = """Usage: | usage = """Usage: | ||||||
|   #{$0} [--replace grammar] url |   #{$0} [--replace grammar] url | ||||||
| Examples: | Examples: | ||||||
| @@ -55,13 +54,13 @@ $replace = nil | |||||||
| $verbose = false | $verbose = false | ||||||
|  |  | ||||||
| OptionParser.new do |opts| | OptionParser.new do |opts| | ||||||
| 	opts.banner = usage |   opts.banner = usage | ||||||
| 	opts.on("-v", "--verbose", "Print verbose feedback to STDOUT") do |   opts.on("-v", "--verbose", "Print verbose feedback to STDOUT") do | ||||||
| 		$verbose = true |     $verbose = true | ||||||
| 	end |   end | ||||||
| 	opts.on("-rSUBMODULE", "--replace=SUBMODDULE", "Replace an existing grammar submodule.") do |name| |   opts.on("-rSUBMODULE", "--replace=SUBMODDULE", "Replace an existing grammar submodule.") do |name| | ||||||
| 		$replace = name |     $replace = name | ||||||
| 	end |   end | ||||||
| end.parse! | end.parse! | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -69,8 +68,8 @@ $url = ARGV[0] | |||||||
|  |  | ||||||
| # No URL? Print a usage message and bail. | # No URL? Print a usage message and bail. | ||||||
| unless $url | unless $url | ||||||
| 	warn usage |   warn usage | ||||||
| 	exit 1; |   exit 1; | ||||||
| end | end | ||||||
|  |  | ||||||
| # Ensure the given URL is an HTTPS link | # Ensure the given URL is an HTTPS link | ||||||
| @@ -80,9 +79,9 @@ repo_new = "vendor/grammars/#{parts[:repo]}" | |||||||
| repo_old = parse_submodule($replace) if $replace | repo_old = parse_submodule($replace) if $replace | ||||||
|  |  | ||||||
| if repo_old | if repo_old | ||||||
| 	log "Deregistering: #{repo_old}" |   log "Deregistering: #{repo_old}" | ||||||
| 	`git submodule deinit #{repo_old}` |   `git submodule deinit #{repo_old}` | ||||||
| 	`git rm -rf #{repo_old}` |   `git rm -rf #{repo_old}` | ||||||
| end | end | ||||||
|  |  | ||||||
| log "Registering new submodule: #{repo_new}" | log "Registering new submodule: #{repo_new}" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user