mirror of
				https://github.com/KevinMidboe/linguist.git
				synced 2025-10-29 17:50:22 +00:00 
			
		
		
		
	Add --json option to bin/linguist
This commit is contained in:
		
				
					committed by
					
						 Brandon Black
						Brandon Black
					
				
			
			
				
	
			
			
			
						parent
						
							210cd19876
						
					
				
				
					commit
					e9ac71590f
				
			| @@ -5,6 +5,7 @@ | |||||||
| # | # | ||||||
| require 'linguist' | require 'linguist' | ||||||
| require 'rugged' | require 'rugged' | ||||||
|  | require 'json' | ||||||
|  |  | ||||||
| path = ARGV[0] || Dir.pwd | path = ARGV[0] || Dir.pwd | ||||||
|  |  | ||||||
| @@ -16,15 +17,18 @@ end | |||||||
|  |  | ||||||
| ARGV.shift | ARGV.shift | ||||||
| breakdown = true if ARGV[0] == "--breakdown" | breakdown = true if ARGV[0] == "--breakdown" | ||||||
|  | json_breakdown = true if ARGV[0] == "--json" | ||||||
|  |  | ||||||
| if File.directory?(path) | if File.directory?(path) | ||||||
|   rugged = Rugged::Repository.new(path) |   rugged = Rugged::Repository.new(path) | ||||||
|   repo = Linguist::Repository.new(rugged, rugged.head.target_id) |   repo = Linguist::Repository.new(rugged, rugged.head.target_id) | ||||||
|  |   if !json_breakdown | ||||||
|     repo.languages.sort_by { |_, size| size }.reverse.each do |language, size| |     repo.languages.sort_by { |_, size| size }.reverse.each do |language, size| | ||||||
|       percentage = ((size / repo.size.to_f) * 100) |       percentage = ((size / repo.size.to_f) * 100) | ||||||
|       percentage = sprintf '%.2f' % percentage |       percentage = sprintf '%.2f' % percentage | ||||||
|       puts "%-7s %s" % ["#{percentage}%", language] |       puts "%-7s %s" % ["#{percentage}%", language] | ||||||
|     end |     end | ||||||
|  |   end | ||||||
|   if breakdown |   if breakdown | ||||||
|     puts |     puts | ||||||
|     file_breakdown = repo.breakdown_by_file |     file_breakdown = repo.breakdown_by_file | ||||||
| @@ -35,6 +39,8 @@ if File.directory?(path) | |||||||
|       end |       end | ||||||
|       puts |       puts | ||||||
|     end |     end | ||||||
|  |   elsif json_breakdown | ||||||
|  |     puts JSON.dump(repo.breakdown_by_file) | ||||||
|   end |   end | ||||||
| elsif File.file?(path) | elsif File.file?(path) | ||||||
|   blob = Linguist::FileBlob.new(path, Dir.pwd) |   blob = Linguist::FileBlob.new(path, Dir.pwd) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user