Add --breakdown option for linguist binary

This commit is contained in:
Ted Nyman
2013-12-28 19:56:41 -08:00
parent b498d51889
commit 6a78ac61a7

View File

@@ -1,13 +1,22 @@
#!/usr/bin/env ruby
# linguist — detect language type for a file, or, given a directory, determine language breakdown
# usage: linguist <path>
# usage: linguist <path> [<--breakdown>]
require 'linguist/file_blob'
require 'linguist/repository'
path = ARGV[0] || Dir.pwd
# special case if not given a directory but still given the --breakdown option
if path == "--breakdown"
path = Dir.pwd
breakdown = true
end
ARGV.shift
breakdown = true if ARGV[0] == "--breakdown"
if File.directory?(path)
repo = Linguist::Repository.from_directory(path)
repo.languages.sort_by { |_, size| size }.reverse.each do |language, size|
@@ -15,10 +24,12 @@ if File.directory?(path)
percentage = sprintf '%.2f' % percentage
puts "%-7s %s" % ["#{percentage}%", language]
end
puts
breakdown = repo.breakdown_by_file
breakdown.each do |lang, files|
puts "#{lang}: #{files}"
if breakdown
puts
breakdown = repo.breakdown_by_file
breakdown.each do |lang, files|
puts "#{lang}: #{files}"
end
end
elsif File.file?(path)
blob = Linguist::FileBlob.new(path, Dir.pwd)