Last active
August 29, 2015 14:11
Homebrew-Cask todo lister
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$todos=[]; | |
class todo | |
{ | |
public $file; | |
public $msg; | |
public $linenum; | |
public $text; | |
function __construct($file,$line,$linenum) | |
{ | |
$file=explode("homebrew-cask/",$file)[1]; | |
$done=false; | |
$line=trim(explode("# todo",$line)[1]); | |
if($line[0]==":") // handle todo: foo | |
{ | |
$msg=explode(": ",$line)[1]; | |
} | |
else if($line[0]==",") // handle todo, foo | |
{ | |
$msg=explode(", ",$line)[1]; | |
} | |
else if($line!=="") | |
{ | |
$msg=$line; | |
} | |
else | |
{ | |
$msg="(none provided)"; | |
} | |
if($done) | |
{ | |
$text= "- [X] \"$msg\" in $file line $linenum".PHP_EOL; | |
} | |
else | |
{ | |
$text="- [ ] \"$msg\" in $file line $linenum".PHP_EOL; | |
} | |
list($this->file,$this->msg,$this->linenum,$this->text)=[$file,$msg,$linenum,$text]; | |
} | |
public function __toString() | |
{ | |
return $this->text; | |
} | |
} | |
function find_all_files($dir) | |
{ | |
$root = scandir($dir); | |
foreach($root as $value) | |
{ | |
if($value === '.' || $value === '..' || $value === ".git") {continue;} | |
if(is_file("$dir/$value")) {$result[]="$dir/$value";continue;} | |
foreach(find_all_files("$dir/$value") as $value) | |
{ | |
$result[]=$value; | |
} | |
} | |
return $result; | |
} | |
$files=find_all_files("homebrew-cask/Casks"); | |
foreach($files as $file) | |
{ | |
$contents=explode("\n",file_get_contents($file)); | |
$i=0; | |
foreach($contents as $line) | |
{ | |
$i++; | |
if(strpos($line,"# todo")!==FALSE) | |
{ | |
$todo=new todo($file,$line,$i); | |
if($todo->msg=="improve this machine-generated value") | |
{ | |
$j++; | |
continue; | |
} | |
echo $todo; | |
} | |
} | |
} | |
echo "Plus $j \"improve this machine-generated value\""; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment