Class: Jgit::Project
- Inherits:
-
Thor
- Object
- Thor
- Jgit::Project
- Defined in:
- lib/jgit.rb
Constant Summary collapse
- PROMPT_TASK =
"key in project name:"
Instance Method Summary collapse
- #add(path = nil, name = nil) ⇒ Object
- #chgrp(name = nil) ⇒ Object
- #commit ⇒ Object
- #diff ⇒ Object
- #exe(command) ⇒ Object
- #fetch ⇒ Object
- #list(show = true, group = nil) ⇒ Object
- #pull ⇒ Object
- #push ⇒ Object
- #remove(name = nil) ⇒ Object
- #rename(name = nil, new_name = nil) ⇒ Object
- #status ⇒ Object
- #version ⇒ Object
Instance Method Details
#add(path = nil, name = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/jgit.rb', line 18 def add(path = nil, name = nil) group = get_group path = prompt("key in project path:(empty for current dir)", Dir.pwd) if path.nil? path = File.(path) jexit "no such dir" unless File.directory?(path) name = prompt("key in project name:(empty for current dir)", File.basename(Dir.getwd)) if name.nil? data = list(false, group) data[name] = path save_data(project_path(group), data.to_json) end |
#chgrp(name = nil) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/jgit.rb', line 173 def chgrp(name = nil) group = Group.new name = group.select_group(name) data = group.list(false) name = "" if name == "default" if name.empty? || data.include?(name) puts "switch to #{name} group" save_data(CURRENT_GROUP, name) else jexit "no such group" end end |
#commit ⇒ Object
103 104 105 |
# File 'lib/jgit.rb', line 103 def commit exe "git add -A && git commit" end |
#diff ⇒ Object
135 136 137 |
# File 'lib/jgit.rb', line 135 def diff exe "git diff ." end |
#exe(command) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/jgit.rb', line 153 def exe(command) list = list(false, get_group) jexit "no project, use 'jgit add' to add project first" if list.empty? list.each do |name, path| if ![:project].nil? && [:project] != name next end puts "" puts " - Task:#{bold(name)}" Dir.chdir(path) system command end end |
#fetch ⇒ Object
119 120 121 |
# File 'lib/jgit.rb', line 119 def fetch exe "git fetch" end |
#list(show = true, group = nil) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/jgit.rb', line 37 def list(show = true, group = nil) group = get_group(group) data = load_obj(project_path(group), Hash) if show data.each do |key, val| puts "#{key}: #{val}" end end data end |
#pull ⇒ Object
127 128 129 |
# File 'lib/jgit.rb', line 127 def pull exe "git pull" end |
#push ⇒ Object
143 144 145 |
# File 'lib/jgit.rb', line 143 def push exe "git push" end |
#remove(name = nil) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/jgit.rb', line 54 def remove(name = nil) group = get_group if name.nil? data = list(true, group) name = prompt(PROMPT_TASK) else data = list(false, group) end if data.delete(name).nil? jexit "no such project" else save_data(project_path(group), data.to_json) end end |
#rename(name = nil, new_name = nil) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/jgit.rb', line 76 def rename(name = nil, new_name = nil) group = get_group if name.nil? data = list(true, group) name = prompt(PROMPT_TASK) else data = list(false, group) end new_name = prompt("key in new project name:", File.basename(Dir.getwd)) if new_name.nil? jexit "new_name exist" if data.include?(new_name) result = data.delete(name) if result.nil? jexit "no such project" else data[new_name] = result save_data(project_path(group), data.to_json) end end |
#status ⇒ Object
111 112 113 |
# File 'lib/jgit.rb', line 111 def status exe "git status" end |
#version ⇒ Object
193 194 195 196 |
# File 'lib/jgit.rb', line 193 def version puts "jgit #{Jgit::VERSION} -- jgit is a git management tool in Ruby" puts "visit https://github.com/Jintin/jgit for more information" end |