93 lines
2.9 KiB
Plaintext
93 lines
2.9 KiB
Plaintext
|
|
class console {
|
|
public static function info($fmt,...$arg) {
|
|
self::_log("info",$fmt,...$arg);
|
|
}
|
|
public static function debug($fmt,...$arg) {
|
|
self::_log("debug",$fmt,...$arg);
|
|
}
|
|
public static function notice($fmt,...$arg) {
|
|
self::_log("notice",$fmt,...$arg);
|
|
}
|
|
public static function warning($fmt,...$arg) {
|
|
self::_log("warning",$fmt,...$arg);
|
|
}
|
|
public static function error($fmt,...$arg) {
|
|
self::_log("error",$fmt,...$arg);
|
|
}
|
|
private static function _log($level,$fmt,...$arg) {
|
|
switch ($level) {
|
|
case "info":
|
|
$outfmt = "\e[92m\e[1m-¤- \e[21m%s\e[0m";
|
|
break;
|
|
case "debug":
|
|
$outfmt = "\e[32m ¤ %s\e[0m";
|
|
break;
|
|
case "notice":
|
|
$outfmt = "\e[33m\e[1m ~ \e[21m%s\e[0m";
|
|
break;
|
|
case "warning":
|
|
$outfmt = "\e[93m\e[1m<!> \e[21m%s\e[0m";
|
|
break;
|
|
case "error":
|
|
$outfmt = "\e[91m\e[1m[#] \e[21m%s\e[0m";
|
|
break;
|
|
default:
|
|
$outfmt = "%s";
|
|
}
|
|
printf($outfmt, sprintf(rtrim($fmt)."\n", ...$arg));
|
|
}
|
|
public function confirm($question, $defaultValue=false)
|
|
{
|
|
while (true) {
|
|
printf("\e[94;1m=?= \e[21m%s \e[36m[\e[96m%s\e[36m]? \e[0m", $question, $defaultValue?"Y/n":"y/N");
|
|
$read = strtolower(trim(fgets(STDIN)));
|
|
if ($read == "y") {
|
|
return true;
|
|
} elseif ($read == "n") {
|
|
return false;
|
|
} else {
|
|
return $defaultValue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
class http {
|
|
public static function download($url, $dest) {
|
|
$progress = new NoccyLabs\Downloader\BarProgress();
|
|
$dl = new NoccyLabs\Downloader\Downloader($url, $dest, $progress);
|
|
$dl->start();
|
|
}
|
|
}
|
|
|
|
|
|
class shell {
|
|
private static $chdir_path;
|
|
public static function chdir($path) {
|
|
self::$chdir_path = $path;
|
|
console::debug("Setting working directory to {$path}");
|
|
}
|
|
public static function exec($command, ...$vars) {
|
|
$vars = array_map("escapeshellarg", $vars);
|
|
$exec = sprintf($command, ...$vars);
|
|
console::debug("| $ %s", $exec);
|
|
if (self::$chdir_path) {
|
|
$exec = sprintf("cd %s && %s", escapeshellarg(self::$chdir_path), $exec);
|
|
}
|
|
passthru($exec);
|
|
}
|
|
public static function execAndReturn($command, ...$vars) {
|
|
$vars = array_map("escapeshellarg", $vars);
|
|
$exec = sprintf($command, ...$vars);
|
|
$output = null;
|
|
$status = null;
|
|
console::debug("| $ %s", $exec);
|
|
exec($exec, $output, $status);
|
|
if (self::$chdir_path) {
|
|
$exec = sprintf("cd %s && %s", escapeshellarg(self::$chdir_path), $exec);
|
|
}
|
|
return $output;
|
|
}
|
|
}
|