Class: HackathonDrone::CLI
- Inherits:
-
Thor
- Object
- Thor
- HackathonDrone::CLI
- Defined in:
- lib/hackathon_drone/cli.rb
Instance Method Summary collapse
- #analyze ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #monitor ⇒ Object
- #reset ⇒ Object
- #subscribe(team_name, host = "hackathon-dashboard.herokuapp.com", port = 80) ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
18 19 20 21 22 23 |
# File 'lib/hackathon_drone/cli.rb', line 18 def initialize(*) super project = `git rev-parse --show-toplevel`.strip.split('/').last @config = HackathonDrone::Configuration.new(project) end |
Instance Method Details
#analyze ⇒ Object
107 108 109 |
# File 'lib/hackathon_drone/cli.rb', line 107 def analyze puts Git::BranchStats.analyze end |
#monitor ⇒ Object
54 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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/hackathon_drone/cli.rb', line 54 def monitor unless team = @config.get('team') puts "You first need to subscribe!" exit end Curses.noecho Curses.curs_set(0) Curses.init_screen begin Curses.setpos(0,0) Curses.addstr "Monitoring #{@config.project}" Curses.refresh Curses.setpos(2,0) while true # Validate that the venue is in progress venue = HackathonDrone::REST.get(@config.get('host'), @config.get('port'), VENUE_PATH.gsub(/:id/, team['venue_id'].to_s)) if venue and venue['state'] == 'started' team_stats = Git::BranchStats.analyze team = @config.set('team', HackathonDrone::REST.put(@config.get('host'), @config.get('port'), TEAM_PATH.gsub(/:id/, team['id'].to_s).gsub(/:venue_id/, team['venue_id'].to_s), team_stats)) report(team, team_stats) else if venue if venue['state'] == "open" Curses.addstr 'Venue is still open, waiting for venue to start...' else puts "This venue is '#{venue['state']}'! It is not in progress." exit end else puts "Venue #{team['venue_id']} was not found" exit end end Curses.refresh # Re-analyze in x seconds sleep 10 end ensure Curses.close_screen end end |
#reset ⇒ Object
102 103 104 |
# File 'lib/hackathon_drone/cli.rb', line 102 def reset @config.reset end |
#subscribe(team_name, host = "hackathon-dashboard.herokuapp.com", port = 80) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/hackathon_drone/cli.rb', line 26 def subscribe(team_name, host = "hackathon-dashboard.herokuapp.com", port = 80) if @config.get('team') puts "Already subscribed as #{@config.get('team')['name']}" exit end # 1. Get the venues venues = HackathonDrone::REST.get(host, port, VENUES_PATH) # 2. Find the first open venue open_venue = venues.find {|venue| venue['state'] == 'open'} # 3. Bail out if no open venue is found unless open_venue puts "No open venue yet, wait until the organizer opens the venue!" exit end team = HackathonDrone::REST.post(host, port, TEAMS_PATH.gsub(/:venue_id/, open_venue['id'].to_s), {:name => team_name}) if team @config.set('team', team) @config.set('host', host) @config.set('port', port) puts "Your team has been subscribed!" end end |