Updated stubs

This commit is contained in:
Chris 2016-12-02 14:33:19 +01:00
parent 9f8cf0bf38
commit b5d3754b2f
3 changed files with 112 additions and 3 deletions

View File

@ -8,7 +8,7 @@ class HotfixApplication extends Application
{ {
public function __construct() public function __construct()
{ {
parent::__construct("Hotfix", APP_VERSION." (".PHAR_BUILD_DATE.")"); parent::__construct("Hotfix", APP_VERSION.(defined('PHAR_BUILD_DATE')?" (".PHAR_BUILD_DATE.")":""));
$this->add(new Command\ApplyCommand()); $this->add(new Command\ApplyCommand());
$this->add(new Command\SignCommand()); $this->add(new Command\SignCommand());
} }

View File

@ -12,6 +12,23 @@ function exec() {
fi fi
# rm $LOG # rm $LOG
} }
function task() {
echo -e "\e[36;1m[exec]\e[36;21m $*\e[0m"
$@ > /dev/null & spinner
}
function info() { function info() {
echo -e "\e[32;1m[info]\e[32;21m $*\e[0m" echo -e "\e[32;1m[info]\e[32;21m $*\e[0m"
} }
function spinner() {
local pid=$!
local delay=0.5
local spinstr='|/-\'
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
local temp=${spinstr#?}
printf "%c" $spinstr
local spinstr=$temp${spinstr%"$temp"}
sleep $delay
printf "\b"
done
printf " \b"
}

92
src/stubs/php.stub Normal file
View File

@ -0,0 +1,92 @@
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;
}
}