From 6a78ac61a778fb65c785f805a14b4d9669a152c8 Mon Sep 17 00:00:00 2001 From: Ted Nyman Date: Sat, 28 Dec 2013 19:56:41 -0800 Subject: [PATCH] Add --breakdown option for linguist binary --- bin/linguist | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/bin/linguist b/bin/linguist index 18ea3431..17008fe0 100755 --- a/bin/linguist +++ b/bin/linguist @@ -1,13 +1,22 @@ #!/usr/bin/env ruby # linguist — detect language type for a file, or, given a directory, determine language breakdown -# usage: linguist +# usage: linguist [<--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)