Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 66 lines (52 sloc) 1.43 KB
#!/usr/bin/env php
<?php
echo "\n";
$path = './...';
$args = array_merge(array(
// no args yet
), parseArgs($argv));
$fileList = array();
foreach ($args as $key => $arg) {
if (is_numeric($key)) {
$fileList[] = $arg;
}
}
if (count($fileList) == 0) {
die('Provide at least one file argument to the revert command');
}
$files = implode(' ', $fileList);
$ret = `p4 open $files && p4 revert $files`;
die($ret);
// ================
// HELPER FUNCTIONS
// ================
function parseArgs($argv){
array_shift($argv);
$out = array();
foreach ($argv as $arg){
if (substr($arg,0,2) == '--'){
$eqPos = strpos($arg,'=');
if ($eqPos === false){
$key = substr($arg,2);
$out[$key] = isset($out[$key]) ? $out[$key] : true;
} else {
$key = substr($arg,2,$eqPos-2);
$out[$key] = substr($arg,$eqPos+1);
}
} else if (substr($arg,0,1) == '-'){
if (substr($arg,2,1) == '='){
$key = substr($arg,1,1);
$out[$key] = substr($arg,3);
} else {
$chars = str_split(substr($arg,1));
foreach ($chars as $char){
$key = $char;
$out[$key] = isset($out[$key]) ? $out[$key] : true;
}
}
} else {
$out[] = $arg;
}
}
return $out;
}
Jump to Line
Something went wrong with that request. Please try again.