Class: Interface
- Inherits:
-
Object
- Object
- Interface
- Defined in:
- lib/interface.rb
Instance Attribute Summary collapse
-
#assig_path ⇒ Object
readonly
Returns the value of attribute assig_path.
-
#client ⇒ Object
Returns the value of attribute client.
-
#config ⇒ Object
Returns the value of attribute config.
-
#deep ⇒ Object
Returns the value of attribute deep.
-
#issues_list ⇒ Object
readonly
Returns the value of attribute issues_list.
-
#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.
-
#orgs_repos ⇒ Object
readonly
Returns the value of attribute orgs_repos.
-
#repo_path ⇒ Object
readonly
Returns the value of attribute repo_path.
-
#repos_list ⇒ Object
readonly
Returns the value of attribute repos_list.
-
#sysbh ⇒ Object
readonly
Returns the value of attribute sysbh.
-
#teamlist ⇒ Object
readonly
Returns the value of attribute teamlist.
-
#teams_repos ⇒ Object
readonly
Returns the value of attribute teams_repos.
Instance Method Summary collapse
-
#cd(path) ⇒ Object
Go to the path, depends with the scope if you are in user scope, first searchs Orgs then Repos, etc.
- #cdassig(path) ⇒ Object
-
#cdback(returnall) ⇒ Object
Go back to any level.
- #cdrepo(path) ⇒ Object
- #collaborators ⇒ Object
- #commits ⇒ Object
- #get_teamlist(data) ⇒ Object
- #help ⇒ Object
-
#initialize ⇒ Interface
constructor
A new instance of Interface.
- #orgs ⇒ Object
- #people ⇒ Object
- #prompt ⇒ Object
- #repos(all) ⇒ Object
-
#run(config_path, argv_token, user) ⇒ Object
Main program.
-
#set(path) ⇒ Object
set in the given path repository, first search in the list, then do the github query if list is empty.
- #show_forks ⇒ Object
Constructor Details
#initialize ⇒ Interface
Returns a new instance of Interface.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/interface.rb', line 31 def initialize @sysbh=Sys.new() @repos_list=[]; @orgs_repos=[]; @teams_repos=[]; @orgs_list=[]; @teamlist=[] @repo_path='' =@sysbh.parse trap("SIGINT") { throw :ctrl_c } catch :ctrl_c do begin if [:user]==nil && [:token]==nil && [:path]!=nil self.run([:path],[:token],[:user]) else self.run("#{ENV['HOME']}/.ghedsh",[:token],[:user]) end rescue SystemExit, Interrupt raise rescue Exception => e puts "exit" puts e end end end |
Instance Attribute Details
#assig_path ⇒ Object (readonly)
Returns the value of attribute assig_path.
29 30 31 |
# File 'lib/interface.rb', line 29 def assig_path @assig_path end |
#client ⇒ Object
Returns the value of attribute client.
26 27 28 |
# File 'lib/interface.rb', line 26 def client @client end |
#config ⇒ Object
Returns the value of attribute config.
25 26 27 |
# File 'lib/interface.rb', line 25 def config @config end |
#deep ⇒ Object
Returns the value of attribute deep.
27 28 29 |
# File 'lib/interface.rb', line 27 def deep @deep end |
#issues_list ⇒ Object (readonly)
Returns the value of attribute issues_list.
29 30 31 |
# File 'lib/interface.rb', line 29 def issues_list @issues_list end |
#memory ⇒ Object
Returns the value of attribute memory.
28 29 30 |
# File 'lib/interface.rb', line 28 def memory @memory end |
#option ⇒ Object (readonly)
Returns the value of attribute option.
24 25 26 |
# File 'lib/interface.rb', line 24 def option @option end |
#orgs_list ⇒ Object (readonly)
Returns the value of attribute orgs_list.
29 30 31 |
# File 'lib/interface.rb', line 29 def orgs_list @orgs_list end |
#orgs_repos ⇒ Object (readonly)
Returns the value of attribute orgs_repos.
29 30 31 |
# File 'lib/interface.rb', line 29 def orgs_repos @orgs_repos end |
#repo_path ⇒ Object (readonly)
Returns the value of attribute repo_path.
29 30 31 |
# File 'lib/interface.rb', line 29 def repo_path @repo_path end |
#repos_list ⇒ Object (readonly)
Returns the value of attribute repos_list.
29 30 31 |
# File 'lib/interface.rb', line 29 def repos_list @repos_list end |
#sysbh ⇒ Object (readonly)
Returns the value of attribute sysbh.
24 25 26 |
# File 'lib/interface.rb', line 24 def sysbh @sysbh end |
#teamlist ⇒ Object (readonly)
Returns the value of attribute teamlist.
29 30 31 |
# File 'lib/interface.rb', line 29 def teamlist @teamlist end |
#teams_repos ⇒ Object (readonly)
Returns the value of attribute teams_repos.
29 30 31 |
# File 'lib/interface.rb', line 29 def teams_repos @teams_repos end |
Instance Method Details
#cd(path) ⇒ Object
Go to the path, depends with the scope if you are in user scope, first searchs Orgs then Repos, etc.
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/interface.rb', line 169 def cd(path) if @deep==ORGS_REPO || @deep==USER_REPO || @deep==TEAM_REPO self.cdrepo(path) end path_split=path.split("/") if path_split.size==1 ##cd con path simple case when @deep==USER @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) @sysbh.add_history_str(1,@teamlist) @deep=2 else #puts "\nNo organization is available with that name" self.set(path) end when @deep == ORGS aux=@teamlist if aux[path]!=nil @config["Team"]=path @config["TeamID"]=@teamlist[path] @deep=TEAM else #puts "\nNo team is available with that name" if cdassig(path)==false self.set(path) end end when @deep == TEAM self.set(path) end else ##CD con path absoluto case when @deep==USER if @orgs_list.empty? @orgs_list=Organizations.new.read_orgs(@client) end aux=@orgs_list if aux.one?{|aux| aux==path_split[0]} @config["Org"]=path_split[0] @deep=ORGS if @teamlist.empty? @teamlist=Teams.new.read_teamlist(@client,@config) end aux=@teamlist if aux[path_split[1]]!=nil @config["Team"]=path_split[1] @config["TeamID"]=@teamlist[path_split[1]] @deep=TEAM if path_split.size>2 self.set(path_split[2]) end else #puts "\nNo team is available with that name" self.set(path_split[1]) end else #puts "\nNo organization is available with that name" self.set(path) end when @deep==ORGS if aux[path_split[0]]!=nil @config["Team"]=path_split[0] @config["TeamID"]=@teamlist[path_split[0]] @deep=TEAM self.set(path_split[1]) else #puts "\nNo team is available with that name" end end end end |
#cdassig(path) ⇒ Object
310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/interface.rb', line 310 def cdassig(path) o=Organizations.new() list=o.get_assigs(@client,@config) if list.one?{|aux| aux==path} @deep=ASSIG @assig_path=path puts "Set in #{@config["Org"]} assignment: #{path}\n\n" return true else puts "No assignment is available with that name" return false end end |
#cdback(returnall) ⇒ Object
Go back to any level
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/interface.rb', line 101 def cdback(returnall) if returnall!=true case when @deep == ORGS @config["Org"]=nil @deep=1 @orgs_repos=[] when @deep == ORGS_REPO if @repo_path=="" @config["Repo"]=nil @deep=2 else aux=@repo_path.split("/") aux.pop if aux.empty? @repo_path="" else @repo_path=aux.join("/") end end when @deep == USER_REPO if @repo_path=="" @config["Repo"]=nil @deep=1 else aux=@repo_path.split("/") aux.pop if aux.empty? @repo_path="" else @repo_path=aux.join("/") end end when @deep == TEAM @config["Team"]=nil @config["TeamID"]=nil @teams_repos=[] @deep=2 when @deep == ASSIG @deep=ORGS @assig_path="" when @deep == TEAM_REPO if @repo_path=="" @config["Repo"]=nil @deep=TEAM else aux=@repo_path.split("/") aux.pop if aux.empty? @repo_path="" else @repo_path=aux.join("/") end end end else @config["Org"]=nil @config["Repo"]=nil @config["Team"]=nil @config["TeamID"]=nil @deep=1 @orgs_repos=[]; @teams_repos=[] @repo_path=""; @assig_path=""; end end |
#cdrepo(path) ⇒ Object
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/interface.rb', line 293 def cdrepo(path) r=Repositories.new() list=[] if @repo_path=="" newpath=path else newpath=@repo_path+"/"+path end list=r.get_files(@client,@config,newpath,false,@deep) if list==nil puts "Wrong path name" else @repo_path=newpath end end |
#collaborators ⇒ Object
416 417 418 419 420 421 |
# File 'lib/interface.rb', line 416 def collaborators() case when @deep==ORGS_REPO Repositories.show_collaborators(@client,@config,1) end end |
#commits ⇒ Object
401 402 403 404 405 406 407 |
# File 'lib/interface.rb', line 401 def commits() c=Repositories.new if @deep==ORGS_REPO || @deep==USER_REPO || @deep==TEAM_REPO c.show_commits(@client,@config,@deep) end print "\n" end |
#get_teamlist(data) ⇒ Object
393 394 395 396 397 398 399 |
# File 'lib/interface.rb', line 393 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 97 98 |
# File 'lib/interface.rb', line 82 def help() h=HelpM.new() case when @deep == USER h.user() when @deep == ORGS h.org() when @deep == ORGS_REPO h.org_repo() when @deep == USER_REPO h.user_repo() when @deep == TEAM h.orgs_teams() when @deep == TEAM_REPO h.team_repo() end end |
#orgs ⇒ Object
324 325 326 327 328 329 330 331 |
# File 'lib/interface.rb', line 324 def orgs() case when @deep==USER @sysbh.add_history_str(2,Organizations.new.show_orgs(@client,@config)) when @deep==ORGS Organizations.new.show_orgs(@client,@config) end end |
#people ⇒ Object
333 334 335 336 337 338 339 340 |
# File 'lib/interface.rb', line 333 def people() case when @deep==ORGS @sysbh.add_history_str(2,Organizations.new.show_organization_members_bs(@client,@config)) when @deep==TEAM @sysbh.add_history_str(2,Teams.new.show_team_members_bs(@client,@config)) end end |
#prompt ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/interface.rb', line 55 def prompt() case when @deep == USER then return @config["User"]+"> " when @deep == USER_REPO if @repo_path!="" @config["User"]+">"+ "\e[31m#{@config["Repo"]}\e[0m"+">"+"#{@repo_path}"+"> " else return @config["User"]+">"+ "\e[31m#{@config["Repo"]}\e[0m"+"> " end when @deep == ORGS then return @config["User"]+">"+ "\e[34m#{@config["Org"]}\e[0m"+"> " when @deep == ASSIG then return @config["User"]+">"+ "\e[34m#{@config["Org"]}\e[0m"+">"+"\e[35m#{@assig_path}\e[0m"+"> " when @deep == TEAM then return @config["User"]+">"+"\e[34m#{@config["Org"]}\e[0m"+">"+"\e[32m#{@config["Team"]}\e[0m"+"> " when @deep == TEAM_REPO if @repo_path!="" return @config["User"]+">"+"\e[34m#{@config["Org"]}\e[0m"+">"+"\e[32m#{@config["Team"]}\e[0m"+">"+"\e[31m#{@config["Repo"]}\e[0m"+">"+"#{@repo_path}"+"> " else return @config["User"]+">"+"\e[34m#{@config["Org"]}\e[0m"+">"+"\e[32m#{@config["Team"]}\e[0m"+">"+"\e[31m#{@config["Repo"]}\e[0m"+"> " end when @deep == ORGS_REPO then if @repo_path!="" return @config["User"]+">"+"\e[34m#{@config["Org"]}\e[0m"+">"+"\e[31m#{@config["Repo"]}\e[0m"+">"+"#{@repo_path}"+"> " else return @config["User"]+">"+"\e[34m#{@config["Org"]}\e[0m"+">"+"\e[31m#{@config["Repo"]}\e[0m"+"> " end end end |
#repos(all) ⇒ Object
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
# File 'lib/interface.rb', line 342 def repos(all) repo=Repositories.new() case when @deep == USER if @repos_list.empty? if all==false list=repo.show_repos(@client,@config,USER,nil) @sysbh.add_history_str(2,list) @repos_list=list else list=repo.get_repos_list(@client,@config,USER) @sysbh.add_history_str(2,list) @repos_list=list puts list end else @sysbh.showcachelist(@repos_list,nil) end when @deep ==ORGS if @orgs_repos.empty? if all==false list=repo.show_repos(@client,@config,ORGS,nil) @sysbh.add_history_str(2,list) @orgs_repos=list else list=repo.show_repos(@client,@config,ORGS) @sysbh.add_history_str(2,list) @repos_list=list puts list end else @sysbh.showcachelist(@orgs_repos,nil) end when @deep==TEAM if @teams_repos.empty? if all==false list=repo.show_repos(@client,@config,TEAM,nil) @sysbh.add_history_str(2,list) @teams_repos=list else list=repo.show_repos(@client,@config,TEAM) @sysbh.add_history_str(2,list) @repos_list=list puts list end else @sysbh.showcachelist(@teams_repos,nil) end end end |
#run(config_path, argv_token, user) ⇒ Object
Main program
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 |
# File 'lib/interface.rb', line 424 def run(config_path, argv_token,user) ex=1 opscript=[] @sysbh.write_initial_memory() HelpM.new.welcome() o=Organizations.new t=Teams.new r=Repositories.new s=Sys.new # orden de búsqueda: ~/.ghedsh.json ./ghedsh.json ENV["ghedsh"] --configpath path/to/file.json #control de carga de parametros en el logueo de la aplicacion 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=USER if @client!=nil @sysbh.add_history_str(2,Organizations.new.read_orgs(@client)) end while ex != 0 if opscript.empty? op=Readline.readline(self.prompt,true) opcd=op.split else op=opscript[0] opcd=op.split opscript.delete(opscript[0]) end 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(false) when op == "people" then self.people() when op == "teams" #then self.teams() if @deep==ORGS t.show_teams_bs(@client,@config) end when op == "commits" then self.commits() when op == "issues" if @deep==ORGS_REPO || @deep==USER_REPO || @deep==TEAM_REPO @issues_list=r.show_issues(@client,@config,@deep) end when op == "col" then self.collaborators() when op == "forks" then self.show_forks() when op == "groups" if @deep==ORGS t.list_groups(@client,@config) end when op == "info" if @deep=ASSIG then o.show_assig_info(@config,@assig_path) end when op== "add_repo" if @deep=ASSIG then o.add_repo_to_assig(@client,@config,@assig_path) end when op== "add_group" if @deep=ASSIG then o.add_group_to_assig(@client,@config,@assig_path) end when op == "version" puts "GitHub Education Shell v#{Ghedsh::VERSION}" when op == "assignments" if @deep==ORGS o.show_assignments(@client,@config) end when op =="make" if @deep==ASSIG o.make_assig(@client,@config,@assig_path) end end if opcd[0]=="issue" and opcd.size>1 issfound=0 @issues_list=r.get_issues(@client,@config,@deep) if @issues_list!=nil @issues_list.each do |i| if i[:number]==opcd[1].to_i puts "##{i[:number]} state: #{i[:state]} -> #{i[:title]} \n" puts "#{i[:body]}" issfound=1 end end end if issfound==0 puts "Issue not found" end puts "\n" end if opcd[0]=="cd" and opcd[1]!=".." if opcd[1]=="/" or opcd.size==1 self.cdback(true) else if opcd[1]=="repo" and opcd.size>2 self.set(opcd[2]) else self.cd(opcd[1]) end end end if opcd[0]=="do" and opcd.size>1 opscript=s.load_script(opcd[1]) end if opcd[0]=="set" self.set(opcd[1]) end if opcd[0]=="repos" and opcd.size==1 self.repos(false) end if opcd[0]=="repos" and opcd.size>1 ##Busca con expresion regular, si no esta en la cache realiza la consulta if opcd[1]=="-all" || opcd[1]=="-a" self.repos(true) else case when @deep==USER if @repos_list.empty? r.show_repos(@client,@config,@deep,opcd[1]) @repos_list=r.get_repos_list(@client,@config,@deep) else @sysbh.showcachelist(@repos_list,opcd[1]) end when @deep==ORGS if @orgs_repos.empty? r.show_repos(@client,@config,@deep,opcd[1]) @orgs_repos=r.get_repos_list(@client,@config,@deep) else @sysbh.showcachelist(@orgs_repos,opcd[1]) end when @deep==TEAM if @teams_repos.empty? r.show_repos(@client,@config,@deep,opcd[1]) @teams_repos=r.get_repos_list(@client,@config,@deep) else @sysbh.showcachelist(@teams_repos,opcd[1]) end end end end if opcd[0]=="add_team_member" t.add_to_team(@client,@config,opcd[1]) end if opcd[0]=="new_team" and opcd.size==2 t.create_team(@client,@config,opcd[1]) @teamlist=t.read_teamlist(@client,@config) @sysbh.add_history_str(1,@teamlist) end if opcd[0]=="new_issue" and opcd.size==1 if @deep==ORGS_REPO || @deep==USER_REPO || @deep==TEAM_REPO r.create_issue(@client,@config,@deep) end end if opcd[0]=="close_issue" and opcd.size==2 if @deep==ORGS_REPO || @deep==USER_REPO || @deep==TEAM_REPO r.close_issue(@client,@config,@deep,opcd[1]) end end if opcd[0]=="open_issue" and opcd.size==2 if @deep==ORGS_REPO || @deep==USER_REPO || @deep==TEAM_REPO r.open_issue(@client,@config,@deep,opcd[1]) end end if opcd[0]=="rm_team" t.delete_team(@client,@teamlist[opcd[1]]) self.quit_history(@teamlist[opcd[1]]) @teamlist=t.read_teamlist(@client,@config) @sysbh.add_history_str(1,@teamlist) end if opcd[0]=="rm_group" and opcd.size==2 if @deep==ORGS t.delete_group(@config,opcd[1]) end end if opcd[0]=="new_team" and opcd.size>2 t.create_team_with_members(@client,@config,opcd[1],opcd[2..opcd.size]) @teamlist=t.read_teamlist(@client,@config) @sysbh.add_history_str(1,@teamlist) end if opcd[0]=="new_repository" and opcd.size==2 r.create_repository(@client,@config,opcd[1],@deep) end if opcd[0]=="new_assignment" and opcd.size>1 #2 case when @deep==ORGS #r.create_repository_by_teamlist(@client,@config,opcd[1],opcd[2,opcd.size],self.get_teamlist(opcd[2,opcd.size])) o.create_assig(@client,@config,opcd[1]) end end if opcd[0]=="new_group" and opcd.size>2 if @deep==ORGS t.new_group(@client,@config,opcd[1],opcd[2..opcd.size-1]) end end if opcd[0]=="clone" if opcd.size==2 r.clone_repo(@client,@config,opcd[1],@deep) end if opcd.size==1 && (@deep==USER_REPO || @deep==TEAM_REPO || @deep==ORGS_REPO) r.clone_repo(@client,@config,nil,@deep) end end if op.match(/^!/) op=op.split("!") s.execute_bash(op[1]) end if opcd[0]=="clone" and opcd.size>2 #r.clone_repo(@client,@config,opcd[1]) end if opcd[0]=="files" if opcd.size==1 r.get_files(@client,@config,@repo_path,true,@deep) else r.get_files(@client,@config,opcd[1],true,@deep) end end if opcd[0]=="cat" and opcd.size>1 r.cat_file(@client,@config,opcd[1],@deep) end end end |
#set(path) ⇒ Object
set in the given path repository, first search in the list, then do the github query if list is empty
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 |
# File 'lib/interface.rb', line 247 def set(path) reposlist=Repositories.new() case when @deep==USER @config["Repo"]=path if @repos_list.empty? == false reposlist=@repos_list else reposlist=reposlist.get_repos_list(@client,@config,@deep) end if reposlist.one?{|aux| aux==path} @deep=USER_REPO puts "Set in #{@config["User"]} repository: #{path}\n\n" end when @deep==ORGS @config["Repo"]=path if @orgs_repos.empty? == false reposlist=@orgs_repos else reposlist=reposlist.get_repos_list(@client,@config,@deep) end if reposlist.one?{|aux| aux==path} @deep=ORGS_REPO puts "Set in #{@config["Org"]} repository: #{path}\n\n" end when @deep==TEAM @config["Repo"]=path if @teams_repos.empty? == false reposlist=@teams_repos else reposlist=reposlist.get_repos_list(@client,@config,@deep) end if reposlist.one?{|aux| aux==path} @deep=TEAM_REPO puts "Set in #{@config["Team"]} repository: #{path}\n\n" end end #if @deep==USER || @deep==ORGS || @deep==TEAM then puts "No repository is available with that name\n\n" end if @deep==USER || @deep==ORGS || @deep==TEAM puts "\nNo organization is available with that name" puts "\nNo team is available with that name" puts "No repository is available with that name\n\n" end end |
#show_forks ⇒ Object
409 410 411 412 413 414 |
# File 'lib/interface.rb', line 409 def show_forks() case when @deep==ORGS_REPO Repositories.new.show_forks(@client,@config,1) end end |