Class: Interface
- Inherits:
-
Object
- Object
- Interface
- Defined in:
- lib/interface.rb
Constant Summary collapse
- LIST =
['repos', 'exit', 'orgs','help', 'members','teams', 'cd ', 'commits','forks', 'add_team_member ','create_team ','delete_team ','create_repository ','clone_repo '].sort
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#config ⇒ Object
Returns the value of attribute config.
-
#deep ⇒ Object
Returns the value of attribute deep.
-
#memory ⇒ Object
Returns the value of attribute memory.
-
#option ⇒ Object
readonly
Returns the value of attribute option.
-
#orgs_list ⇒ Object
readonly
Returns the value of attribute orgs_list.
-
#teamlist ⇒ Object
readonly
Returns the value of attribute teamlist.
Instance Method Summary collapse
- #add_history(value) ⇒ Object
- #add_history_str(mode, value) ⇒ Object
- #cd(path) ⇒ Object
- #cdback ⇒ Object
- #collaborators ⇒ Object
- #commits ⇒ Object
- #get_teamlist(data) ⇒ Object
- #help ⇒ Object
-
#initialize ⇒ Interface
constructor
A new instance of Interface.
- #members ⇒ Object
- #orgs ⇒ Object
- #prompt ⇒ Object
- #quit_history(value) ⇒ Object
- #repos ⇒ Object
- #run(config_path, argv_token, user) ⇒ Object
-
#set(path) ⇒ Object
set the repo.
- #show_forks ⇒ Object
- #write_memory ⇒ Object
Constructor Details
#initialize ⇒ Interface
Returns a new instance of Interface.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/interface.rb', line 26 def initialize sysbh=Sys.new() =sysbh.parse if [:user]==nil && [:token]==nil && [:path]!=nil self.run([:path],[:token],[:user]) else self.run("#{ENV['HOME']}/.ghedsh",[:token],[:user]) end end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
19 20 21 |
# File 'lib/interface.rb', line 19 def client @client end |
#config ⇒ Object
Returns the value of attribute config.
18 19 20 |
# File 'lib/interface.rb', line 18 def config @config end |
#deep ⇒ Object
Returns the value of attribute deep.
20 21 22 |
# File 'lib/interface.rb', line 20 def deep @deep end |
#memory ⇒ Object
Returns the value of attribute memory.
21 22 23 |
# File 'lib/interface.rb', line 21 def memory @memory end |
#option ⇒ Object (readonly)
Returns the value of attribute option.
17 18 19 |
# File 'lib/interface.rb', line 17 def option @option end |
#orgs_list ⇒ Object (readonly)
Returns the value of attribute orgs_list.
23 24 25 |
# File 'lib/interface.rb', line 23 def orgs_list @orgs_list end |
#teamlist ⇒ Object (readonly)
Returns the value of attribute teamlist.
22 23 24 |
# File 'lib/interface.rb', line 22 def teamlist @teamlist end |
Instance Method Details
#add_history(value) ⇒ Object
37 38 39 40 |
# File 'lib/interface.rb', line 37 def add_history(value) @memory.push(value) self.write_memory end |
#add_history_str(mode, value) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/interface.rb', line 47 def add_history_str(mode,value) if mode==1 value.each do |i| @memory.push(i[0]) self.write_memory end end if mode==2 value.each do |i| @memory.push(i) self.write_memory end end end |
#cd(path) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/interface.rb', line 116 def cd(path) case when @deep==1 @orgs_list=Organizations.new.read_orgs(@client) aux=@orgs_list if aux.one?{|aux| aux==path} @config["Org"]=path @teamlist=Teams.new.read_teamlist(@client,@config) self.add_history_str(1,@teamlist) @deep=2 else puts "No organization is available with that name" end when @deep == 2 aux=@teamlist if aux[path]!=nil @config["Team"]=path @config["TeamID"]=@teamlist[path] @deep=4 else puts "No team is available with that name" end end end |
#cdback ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/interface.rb', line 98 def cdback() case when @deep == 2 @config["Org"]=nil @deep=1 when @deep == 3 @config["Repo"]=nil @deep=2 when @deep == 10 @config["Repo"]=nil @deep=1 when @deep == 4 @config["Team"]=nil @config["TeamID"]=nil @deep=2 end end |
#collaborators ⇒ Object
221 222 223 224 225 226 |
# File 'lib/interface.rb', line 221 def collaborators() case when @deep==3 Repositories.show_collaborators(@client,@config,1) end end |
#commits ⇒ Object
203 204 205 206 207 208 209 210 211 212 |
# File 'lib/interface.rb', line 203 def commits() c=Repositories.new case when @deep==3 c.show_commits(@client,@config,1) when @deep==10 c.show_commits(@client,@config,2) end print "\n" end |
#get_teamlist(data) ⇒ Object
195 196 197 198 199 200 201 |
# File 'lib/interface.rb', line 195 def get_teamlist(data) list=Array.new for i in 0..data.size-1 list.push(@teamlist[data[i]]) end return list end |
#help ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/interface.rb', line 82 def help() h=HelpM.new() case when @deep == 1 h.user() when @deep == 2 h.org() when @deep == 3 h.org_repo() when @deep == 10 h.user_repo() when @deep == 4 h.orgs_teams() end end |
#members ⇒ Object
171 172 173 174 175 176 177 178 |
# File 'lib/interface.rb', line 171 def members() case when @deep==2 self.add_history_str(2,Organizations.new.show_organization_members_bs(@client,@config)) when @deep==4 self.add_history_str(2,Teams.new.show_team_members_bs(@client,@config)) end end |
#orgs ⇒ Object
164 165 166 167 168 169 |
# File 'lib/interface.rb', line 164 def orgs() case when @deep==1 self.add_history_str(2,Organizations.new.show_orgs(@client,@config)) end end |
#prompt ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/interface.rb', line 71 def prompt() case when @deep == 1 then return @config["User"]+"> " when @deep == 10 then return @config["User"]+">"+@config["Repo"]+"> " when @deep == 2 then return @config["User"]+">"+@config["Org"]+"> " when @deep == 4 then return @config["User"]+">"+@config["Org"]+">"+@config["Team"]+"> " when @deep == 5 then return @config["User"]+">"+@config["Org"]+">"+@config["Team"]+">"+@config["Repo"]+"> " when @deep == 3 then return @config["User"]+">"+@config["Org"]+">"+@config["Repo"]+"> " end end |
#quit_history(value) ⇒ Object
42 43 44 45 |
# File 'lib/interface.rb', line 42 def quit_history(value) @memory.pop(value) self.write_memory end |
#repos ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/interface.rb', line 180 def repos() repo=Repositories.new() case when @deep == 1 list=repo.show_repos(@client,@config,1) self.add_history_str(2,list) when @deep ==2 list=repo.show_repos(@client,@config,2) self.add_history_str(2,list) when @deep==4 list=repo.show_repos(@client,@config,3) self.add_history_str(2,list) end end |
#run(config_path, argv_token, user) ⇒ Object
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/interface.rb', line 228 def run(config_path, argv_token,user) ex=1 @memory=[] history=LIST+memory comp = proc { |s| LIST.grep( /^#{Regexp.escape(s)}/ ) } Readline.completion_append_character = "" Readline.completion_proc = comp HelpM.new.welcome() t=Teams.new r=Repositories.new s=Sys.new # orden de búsqueda: ~/.ghedsh.json ./ghedsh.json ENV["ghedsh"] --configpath path/to/file.json if user!=nil @config=s.load_config_user(config_path,user) @client=s.client if @config==nil ex=0 end else @config=s.load_config(config_path,argv_token) @client=s.client end @deep=1 if @client!=nil self.add_history_str(2,Organizations.new.read_orgs(@client)) end while ex != 0 op=Readline.readline(self.prompt,true) opcd=op.split case when op == "exit" then ex=0 s.save_cache(config_path,@config) when op == "help" then self.help() when op == "orgs" then self.orgs() when op == "cd .." then self.cdback() when op == "members" then self.members() when op == "teams" #then self.teams() if @deep==2 t.show_teams_bs(@client,@config) end when op == "commits" then self.commits() when op == "col" then self.collaborators() when op == "forks" then self.show_forks() end if opcd[0]=="cd" and opcd[1]!=".." self.cd(opcd[1]) #else # self.cdback() end if opcd[0]=="set" self.set(opcd[1]) end if opcd[0]=="repos" and opcd.size==1 self.repos() end if opcd[0]=="repos" and opcd.size>1 case when @deep==1 r.show_repos_smart(@client,@config,opcd[1],1) when @deep==2 r.show_repos_smart(@client,@config,opcd[1],2) when @deep==3 r.show_repos_smart(@client,@config,opcd[1],3) end end if opcd[0]=="add_team_member" t.add_to_team(@client,@config,opcd[1]) end if opcd[0]=="create_team" and opcd.size==2 t.create_team(@client,@config,opcd[1]) @teamlist=t.read_teamlist(@client,@config) self.add_history_str(1,@teamlist) end if opcd[0]=="delete_team" t.delete_team(@client,@teamlist[opcd[1]]) self.quit_history(@teamlist[opcd[1]]) @teamlist=t.read_teamlist(@client,@config) self.add_history_str(1,@teamlist) end if opcd[0]=="create_team" and opcd.size>2 t.create_team_with_members(@client,@config,opcd[1],opcd[2..opcd.size]) @teamlist=t.read_teamlist(@client,@config) self.add_history_str(1,@teamlist) end if opcd[0]=="create_repository" and opcd.size==2 r.create_repository(@client,@config,opcd[1],@deep) end if opcd[0]=="create_repository" and opcd.size>2 case when @deep==2 r.create_repository_by_teamlist(@client,@config,opcd[1],opcd[2,opcd.size],self.get_teamlist(opcd[2,opcd.size])) end end if opcd[0]=="clone_repo" and opcd.size==2 r.clone_repo(@client,@config,opcd[1],@deep) end if op.match(/^!/) op=op.split("!") s.execute_bash(op[1]) end if opcd[0]=="clone_repo" and opcd.size>2 #r.clone_repo(@client,@config,opcd[1]) end end end |
#set(path) ⇒ Object
set the repo
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/interface.rb', line 142 def set(path) reposlist=Repositories.new() case when @deep==1 @config["Repo"]=path if reposlist.get_repos_list(@client,@config,@deep).one?{|aux| aux==path} @deep=10 end when @deep==2 @config["Repo"]=path if reposlist.get_repos_list(@client,@config,@deep).one?{|aux| aux==path} @deep=3 end when @deep==4 @config["Repo"]=path if reposlist.get_repos_list(@client,@config,@deep).one?{|aux| aux==path} @deep=5 end end if @deep==1 || @deep==2 || @deep==4 then puts "No repository is available with that name" end end |
#show_forks ⇒ Object
214 215 216 217 218 219 |
# File 'lib/interface.rb', line 214 def show_forks() case when @deep==3 Repositories.new.show_forks(@client,@config,1) end end |
#write_memory ⇒ Object
63 64 65 66 67 68 |
# File 'lib/interface.rb', line 63 def write_memory history=(LIST+@memory).sort comp = proc { |s| history.grep( /^#{Regexp.escape(s)}/ ) } Readline.completion_append_character = "" Readline.completion_proc = comp end |