Module: Bcpm::CLI
- Defined in:
- lib/bcpm/cli.rb
Overview
Command-line interface.
Class Method Summary collapse
-
.help ⇒ Object
Prints the CLI help.
-
.run(args) ⇒ Object
Entry point for commands.
Class Method Details
.help ⇒ Object
Prints the CLI help.
252 253 254 255 256 257 258 259 |
# File 'lib/bcpm/cli.rb', line 252 def self.help print <<END_HELP Battlecode (MIT 6.470) package manager. See the README file for usage instructions. END_HELP end |
.run(args) ⇒ Object
Entry point for commands.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 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 52 53 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 100 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 166 167 168 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 245 246 247 248 249 |
# File 'lib/bcpm/cli.rb', line 9 def self.run(args) if args.length < 1 help exit 1 end case args.first when 'self', 'gem' # Upgrade bcpm. Bcpm::Update.upgrade when 'dist' # Install or upgrade the battlecode distribution. Bcpm::Dist.upgrade when 'reset' # Uninstalls the distribution and players, and removes the config file. Bcpm::Cleanup.run Bcpm::Player.uninstall_all Bcpm::Dist.uninstall Bcpm::Config.reset when 'install' # Add a player project to the workspace, from a git repository. unless Bcpm::Dist.installed? puts "Please install a battlecode distribution first!" exit 1 end if args.length < 2 puts "Please supply the path to the player repository!" exit 1 end exit 1 unless Bcpm::Player.install(args[1], args[2] || 'master') when 'copy', 'copyplayer' # Create a new player project using an existing project as a template. unless Bcpm::Dist.installed? puts "Please install a battlecode distribution first!" exit 1 end if args.length < 3 puts "Please supply the new player name, and the path to the template player repository!" exit 1 end exit 1 unless Bcpm::Player.checkpoint(args[2], args[3] || 'master', args[1]) when 'new', 'newplayer' # Create a new player project from the built-in template. unless Bcpm::Dist.installed? puts "Please install a battlecode distribution first!" exit 1 end if args.length < 2 puts "Please supply the new player name!" exit 1 end exit 1 unless Bcpm::Player.create(args[1]) when 'uninstall', 'remove' # Remove a player project from the workspace. unless Bcpm::Dist.installed? puts "Please install a battlecode distribution first!" exit 1 end if args.length < 2 puts "Please supply the player name!" exit 1 end Bcpm::Player.uninstall args[1] when 'rewire' # Re-write a player project's configuration files. unless Bcpm::Dist.installed? puts "Please install a battlecode distribution first!" exit 1 end if args.length == 1 # Try using the current dir as the player name. args[1, 0] = [File.basename(Dir.pwd)] end if args.length < 2 puts "Please supply the player name!" exit 1 end Bcpm::Player.reconfigure args[1] when 'list', 'ls' # Displays the installed players. unless Bcpm::Dist.installed? puts "Please install a battlecode distribution first!" exit 1 end puts Bcpm::Player.list_active.sort.join("\n") when 'match', 'livematch', 'debugmatch', 'debug' # Run a match in live or headless mode. unless Bcpm::Dist.installed? puts "Please install a battlecode distribution first!" exit 1 end if args.length == 3 # Try using the current dir as a player name. args[1, 0] = [File.basename(Dir.pwd)] end if args.length < 4 puts "Please supply the player names and the map name!" exit 1 end mode = if args[0][0, 4] == 'live' :live elsif args[0][0, 5] == 'debug' :debug else :file end puts Bcpm::Match.run(args[1], args[2], args[3], mode) when 'duel' # Have two players fight it out on all maps. if args.length < 3 puts "Pleas supply the player names!" exit 1 end if args.length >= 4 maps = args[3..-1] else maps = nil end outcome = Bcpm::Duel.duel_pair args[1], args[2], true, maps puts "#{'%+3d' % outcome[:score]} points, " + "#{'%3d' % outcome[:wins].length} wins, " + " #{'%3d' % outcome[:losses].length} losses, " + "#{'%3d' % outcome[:errors].length} errors" when 'rank' # Ranks all the players. if args.length < 2 players = Bcpm::Player.list_active.sort else players = args[1..-1] end outcome = Bcpm::Duel.rank_players players, true outcome.each { |score, player| print "%+4d %s\n" % [score, player] } when 'pit' # Pits one player against all the other players. if args.length < 2 puts "Please supply a player name!" end player = args[1] if args.length >= 3 enemies = args[2..-1] else enemies = Bcpm::Player.list_active.sort - [player] end outcome = Bcpm::Duel.score_player player, enemies, true puts "#{'%+4d' % outcome[:points]} points" outcome[:scores].each do |score, player| print "%+4d vs %s\n" % [score, player] end when 'replay' # Replay a match using its binlog (.rms file). unless Bcpm::Dist.installed? puts "Please install a battlecode distribution first!" exit 1 end if args.length == 1 # Replay the last game. replays = Bcpm::Tests::TestMatch.stashed_replays args[1, 0] = [replays.max] unless replays.empty? end if args.length < 2 puts "Please supply the path to the match binlog (.rms file)!" exit 1 end Bcpm::Match.replay args[1] when 'test' # Run the entire test suite against a player. unless Bcpm::Dist.installed? puts "Please install a battlecode distribution first!" exit 1 end if args.length == 1 # Try using the current dir as the player name. args[1, 0] = [File.basename(Dir.pwd)] end if args.length < 2 puts "Please supply the player name!" exit 1 end Bcpm::Player.run_suite args[1] when 'case', 'testcase', 'livecase', 'live' # Run a single testcase against a player. unless Bcpm::Dist.installed? puts "Please install a battlecode distribution first!" exit 1 end if args.length == 2 # Try using the current dir as the player name. args[1, 0] = [File.basename(Dir.pwd)] end if args.length < 3 puts "Please supply the player name and the testcase name!" exit 1 end Bcpm::Player.run_case args[2], args[0][0, 4] == 'live', args[1] when 'clean', 'cleanup' # Removes all temporaries left behind by crashes. Bcpm::Cleanup.run when 'config', 'set' if args.length < 2 Bcpm::Config.print_config else Bcpm::Config.ui_set(args[1], args[2]) end when 'regen' # Regenerates automatically generated source code. if args.length < 2 puts "Please supply the source file(s)." exit 1 end Bcpm::Regen.run args[1..-1] when 'lsmaps', 'lsmap', 'maps', 'map' # Lists the maps in the distribution. unless Bcpm::Dist.installed? puts "Please install a battlecode distribution first!" exit 1 end puts Bcpm::Dist.maps.sort.join("\n") when 'copymap', 'cpmap' # Clones a distribution map for testing. unless Bcpm::Dist.installed? puts "Please install a battlecode distribution first!" exit 1 end if args.length < 2 puts "Please supply the map name and destination" exit 1 end if args.length < 3 # Default destination. if File.exist?('suite') && File.directory?('suite') FileUtils.mkdir_p 'maps' args[2] = 'suite/maps' else puts "Please supply map destination or cd into a player directory" exit 1 end end Bcpm::Dist.copy_map args[1], args[2] else help exit 1 end end |