add short output

This commit is contained in:
Alexander Popov 2022-08-13 16:23:03 +03:00
parent 5add145cef
commit b9e61ef101
Signed by: iiiypuk
GPG Key ID: D8C9B59A9F04A70C

View File

@ -2,6 +2,7 @@ require "colorize"
require "option_parser" require "option_parser"
VERSION = {{ `shards version "#{__DIR__}"`.chomp.stringify }} VERSION = {{ `shards version "#{__DIR__}"`.chomp.stringify }}
short_output = false
begin begin
OptionParser.parse do |parser| OptionParser.parse do |parser|
@ -12,6 +13,10 @@ begin
exit(0) exit(0)
end end
parser.on "-s", "Short output" do
short_output = true
end
parser.on "-v", "Show version" do parser.on "-v", "Show version" do
puts VERSION puts VERSION
exit(0) exit(0)
@ -28,7 +33,7 @@ if File.exists?(CONFIG_PATH)
repos_dirs = File.read_lines(CONFIG_PATH) repos_dirs = File.read_lines(CONFIG_PATH)
repos_dirs.each { |x| check_repo(x) } repos_dirs.each { |x| check_repo(x, short_output) }
else else
Dir.mkdir_p(File.dirname(CONFIG_PATH)) Dir.mkdir_p(File.dirname(CONFIG_PATH))
File.new(CONFIG_PATH, "w") File.new(CONFIG_PATH, "w")
@ -37,7 +42,7 @@ else
puts " directory created.\n" puts " directory created.\n"
end end
def check_repo(repo_path : String) def check_repo(repo_path : String, show_path)
if !Dir.exists?(repo_path.sub("$HOME", ENV["HOME"])) if !Dir.exists?(repo_path.sub("$HOME", ENV["HOME"]))
return 0 return 0
end end
@ -52,8 +57,13 @@ def check_repo(repo_path : String)
if !ahead_count.empty? if !ahead_count.empty?
print "* #{ahead_count}\t".colorize(:red).mode(:bold) print "* #{ahead_count}\t".colorize(:red).mode(:bold)
print repo_name.colorize(:yellow) print repo_name.colorize(:yellow)
if !show_path
print " [" print " ["
print repo_path.colorize(:light_magenta) print repo_path.colorize(:light_magenta)
puts "]" puts "]"
else
puts
end
end end
end end