lib/yac.rb in yac-0.0.1 vs lib/yac.rb in yac-0.0.2

- old
+ new

@@ -1,21 +1,24 @@ %w(rubygems git fileutils yaml).each {|f| require f} module Yac extend self - CHITRC = File.join("#{ENV['HOME']}",".chitrc") - FileUtils.cp(File.join(File.dirname(__FILE__), "..","resources","yacrc"), CHITRC) unless File.exist?(CHITRC) + YACRC = File.join("#{ENV['HOME']}",".yacrc") + FileUtils.cp(File.join(File.dirname(__FILE__), "..","resources","yacrc"), YACRC) unless File.exist?(YACRC) CONFIG = YAML.load_file(File.join(ENV['HOME'],".yacrc")) CONFIG["root"] ||= File.join(ENV['HOME'],".yac") @main_path = File.join(CONFIG["root"],"/main/") @pri_path = File.join(CONFIG["root"],"/private/") - @main_git = Git.open(@main_path) - @pri_git = Git.open(@pri_path) + @main_git = Git.open(@main_path) if File.exist?(@main_path) + @pri_git = Git.open(@pri_path)if File.exist?(@pri_path) def new(args) + unless File.exist?(@main_path) && File.exist?(@pri_path) + return unless init + end @all_result = [] help && exit if args.empty? case args.first when "show" then show(args[1,args.size]) when "name" then search(args[1,args.size],"name") @@ -63,11 +66,11 @@ def rm(args) args.each {|x| rm_single(x)} end def help - format_file(File.dirname(__FILE__)+"/../README") + format_file(File.dirname(__FILE__)+"/../README.rdoc") end def shell(args = "pri") puts "Comming Soon :)" #case args.to_s @@ -192,11 +195,11 @@ def title_of_file(f) f[0..((f.rindex('.')||0) - 1)] end def show_possible_result - puts "\n\033[" + CONFIG["possible_result_title"].to_s + "mALL POSSIBLE RESULT:\n\033[0m\033[" +CONFIG["possible_result_content"].to_s + "m" + @all_result.join("\s"*2) + "\033[0m" unless @all_result.to_s.empty? + puts "\n\033[" + CONFIG["possible_result_title"].to_s + "mALL POSSIBLE RESULT:\033[0m\n \033[" +CONFIG["possible_result_content"].to_s + "m" + @all_result.join("\s"*2) + "\033[0m" unless @all_result.to_s.empty? end def init FileUtils.mkdir_p(CONFIG['root']) if CONFIG['main']['clone-from'] @@ -225,8 +228,10 @@ puts "Private repository initialized." end else puts "Private repository has already been initialized." end + @main_git = Git.open(@main_path) if File.exist?(@main_path) + @pri_git = Git.open(@pri_path)if File.exist?(@pri_path) puts "Repository init done." end end