lib/yac.rb in wosmvp-yac-1.0.1 vs lib/yac.rb in wosmvp-yac-1.0.2

- old
+ new

@@ -23,10 +23,11 @@ case args.first when "show" then show(args[1,args.size]) when "search" then search(args[1,args.size]) when "update" then update(args[1,args.size]) when "push" then push(args[1,args.size]) + when "log" then log(args[1,args.size]) when "add" then add(args[1,args.size]) when "edit" then edit(args[1,args.size]) when /^(help|-h|yac|--help)$/ then help when "sh" then shell(args[1,args.size]) when "rm" then rm(args[1,args.size]) @@ -64,31 +65,38 @@ def search(args) args.each {|x| search_content(x)} end def update(args) - case args.to_s - when /main/ then result = `cd "#{@main_path}" && git pull ` #NOTE There is an bug in the git.gem,Then I will write a new git library use shell command - when /all/ then result = `cd "#{@pri_path}" && git pull && cd "#{@main_path}" && git pull ` - else result = `cd "#{@pri_path}" && git pull` - end - colorful(result,"notice") + git_command(args,'pull') rescue colorful("ERROR: can not update the repository,\n\n#{$!}","warn") end def push(args) - case args.to_s - when /main/ then result=@main_git.push - when /all/ then result=@pri_git.push && result << @main_git.push - else result = @pri_git.push - end - colorful(result,"notice") + git_command(args,'push') rescue colorful("Usage:\nyac push ( main | all )\n\nTry `yac -h` for more help\n\n#{$1}","warn") end + def log(args) + git_command(args,'log --color --date-order --reverse') + end + + def git_command(env,command) + case env.to_s + when /main/ then git_path = [@main_path] + when /all/ then git_path = [@main_path,@pri_path] + else git_path = [@pri_path] + end + + git_path.each do |x| + colorful(x,'filename') + colorful( `cd #{x} && git #{command}` ,"notice") + end + end + def edit(args) args.each {|x| edit_single(x)} end def add(args) @@ -115,10 +123,12 @@ end def rename(args) (colorful("Usage:\nyac mv [orign_name] [new_name]\n\nTry `yac -h` for more help","warn");exit) unless args.size == 2 file = search_name(args[0],"Rename") - new_name = add_file(args[1].sub(/^(@)?/,file =~ /^#{@main_path}/ ? "@":""),file.sub(/.*(\..*)/,'\1')) + #You can use $ yac mv linux.ch linux/ to rename linux.ch to linux/linux.ch + new_filename = args[1].sub(/\/$/,file.sub(/.*\/(.*)(\..*)/,'/\1')).sub(/^(@)?/,file =~ /^#{@main_path}/ ? "@":"") + new_name = add_file(new_filename ,file.sub(/.*(\..*)/,'\1')) if confirm("You Are Renaming #{file} To #{new_name}") prepare_dir(new_name) `mv "#{file}" "#{new_name}"` @working_git.add @working_git.commit_all("#{clean_filename(file)} Renamed to #{clean_filename(new_name)}")