From d54dc7c7996ba6bf3b194b5e8c0f0868e6b3ab10 Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Fri, 23 Sep 2016 21:52:41 +0300 Subject: [PATCH] Still working on it... --- plugin.yml | 10 +- src/Ad5001/Gitable/Main.php | 20 ++-- src/Ad5001/Gitable/Windows.php | 177 ++++++++++++++++++--------------- 3 files changed, 116 insertions(+), 91 deletions(-) diff --git a/plugin.yml b/plugin.yml index cfa77e0..5a536c0 100644 --- a/plugin.yml +++ b/plugin.yml @@ -4,6 +4,12 @@ author: Ad5001 version: 1.0 api: [2.0.0] main: Ad5001\Gitable\Main -commands: [] -permissions: [] +commands: + git: + description: "Main Gitable command" + usage: "/git " + permission: git.command.git +permissions: + git.command.git: + default: op ... \ No newline at end of file diff --git a/src/Ad5001/Gitable/Main.php b/src/Ad5001/Gitable/Main.php index 794b119..55c4101 100644 --- a/src/Ad5001/Gitable/Main.php +++ b/src/Ad5001/Gitable/Main.php @@ -16,6 +16,9 @@ use pocketmine\event\Listener; use pocketmine\plugin\PluginBase; +use pocketmine\utils\TextFormat as C; + + use pocketmine\Server; @@ -31,6 +34,8 @@ use pocketmine\Player; class Main extends PluginBase implements Listener { protected $git; + const PREFIX = C::BLACK . "[" . C::LIGHT_GRAY . "Git" . C::BLACK . "] " . C::LIGHT_GRAY; + public function onEnable() { @@ -58,17 +63,16 @@ class Main extends PluginBase implements Listener { case 'git': - if(count($args) >= 1) { + if(count($args) >= 2) { - if(isset(self::COMMANDS[$args[0]])) { - - $cmd = $args[0]; - - unset($args[0]); - - $sender->sendMessage($this->git->{self::COMMANDS[$cmd][0]}(implode(" ", $args))); + switch($args[0]) { + case "cd": + $this->git->cd($args[1]); + $sender->sendMessage("New path: " . $this->git->getDir()); + break; } + return true; } diff --git a/src/Ad5001/Gitable/Windows.php b/src/Ad5001/Gitable/Windows.php index 223e299..a6bbc85 100644 --- a/src/Ad5001/Gitable/Windows.php +++ b/src/Ad5001/Gitable/Windows.php @@ -21,84 +21,99 @@ use Ad5001\Gitable\Main; class Windows extends GitClient { - - - - - - public function commit(string $message) : string { - return shell_exec("git commit -m \"$message\""); - } - - - public function push(string $to = "github", string $from = "master") : string { - return shell_exec("git push $to $from"); - } - - - public function checkout($branch = null) : string { - return shell_exec("git checkout " . (!is_null($branch) ? $this->getBranch() : $branch)); - } - - - public function getBranch() : string { - $handle = popen('git branch', 'r'); - $read = fread($handle, 2096); - return explode(" ", $read)[1]; - } - - - public function branch($branch = '') : string { - return shell_exec("git branch " . $branch); - } - - - public function start() : string { - return shell_exec("git init"); - } - - - public function init() : string { - return shell_exec("git init"); - } - - public function getDir() { - return $this->dir; - } - - - public function cd($path) : string { - return shell_exec("cd " . $path); - } - - - public function clone($from) : string {} - - - public function log() : string {} - - - public function remove($path) : string {} - - - public function move($path, $newpath) : string {} - - - public function add($path) : string {} - - - public function diff($path) : string {} - - - public function status($path) : string {} - - - public function remote($name, $url) : string {} - - - public function pull($to = "github", $from = "master") : string {} - - - - -} \ No newline at end of file + + + + + + public function commit(string $message) : string { + return shell_exec("git commit -m \"$message\""); + } + + + public function push(string $to = "github", string $from = "master") : string { + return shell_exec("git push $to $from"); + } + + + public function checkout($branch = null) : string { + return shell_exec("git checkout " . (!is_null($branch) ? $this->getBranch() : $branch)); + } + + + public function getBranch() : string { + $handle = popen('git branch', 'r'); + $read = fread($handle, 2096); + return explode(" ", $read)[1]; + } + + + public function branch($branch = '') : string { + return shell_exec("git branch " . $branch); + } + + + public function start() : string { + return shell_exec("git init"); + } + + + public function init() : string { + return shell_exec("git init"); + } + + public function getDir() { + return $this->dir; + } + + + public function cd($path) : string { + if(is_dir($path)) { + $dir = chdir($path); + $this->dir = getcwd(); + return (string) $dir; + } else { + return "Directory $path not found !"; + } + } + + + public function clone($from) : string { + } + + + public function log() : string { + } + + + public function remove($path) : string { + } + + + public function move($path, $newpath) : string { + } + + + public function add($path) : string { + } + + + public function diff($path) : string { + } + + + public function status($path) : string { + } + + + public function remote($name, $url) : string { + } + + + public function pull($to = "github", $from = "master") : string { + } + + + + +}