From 9b64e0fd06c2a8e33ba02318419d1d09af47469f Mon Sep 17 00:00:00 2001 From: Sean Dietrich Date: Thu, 12 Jan 2017 09:30:09 -0800 Subject: [PATCH] Added 0.x branch of code from old repo --- {src/Commands => Commands}/FilerCommand.php | 260 +++++++++++--------- README.md | 29 ++- composer.json | 13 +- 3 files changed, 158 insertions(+), 144 deletions(-) rename {src/Commands => Commands}/FilerCommand.php (56%) diff --git a/src/Commands/FilerCommand.php b/Commands/FilerCommand.php similarity index 56% rename from src/Commands/FilerCommand.php rename to Commands/FilerCommand.php index b1db97d..75df21d 100644 --- a/src/Commands/FilerCommand.php +++ b/Commands/FilerCommand.php @@ -1,12 +1,11 @@ log()->error('Operating system not supported.'); - die; + $this->failure('Operating system not supported.'); } /** - * Class FilerCommand * Opens the Site using an SFTP Client + * + * @command site */ -class FilerCommand extends TerminusCommand implements SiteAwareInterface -{ - - use SiteAwareTrait; +class FilerCommand extends TerminusCommand { + /** + * Object constructor + * + * @param array $options + * @return FilerCommand + */ + + public function __construct(array $options = []) { + $options['require_login'] = true; + parent::__construct($options); + $this->sites = new Sites(); + } /** * Opens the Site using an SFTP Client * - * @authorize + * ## OPTIONS + * + * [--site=] + * : Site to Use * - * @command site:filer - * @aliases filer + * [--env=] + * : Environment * - * @param string $site_env Site & environment in the format `site-name.env` - * @option string $app Application to Open (optional) - * @option string $bundle Bundle Identifier (optional) - * @option boolean $persistant Whether to persist the connection (optional) - * @option string $app_args Application arguments (option) + * [--a=] + * : Application to Open (optional) * - * @usage terminus site:filer . --app= - * @usage terminus site:filer . --bundle= - * @usage terminus site:filer . --app= --persistant= --app_args= + * [--b=] + * : Bundle Identifier (optional) + * + * [--p=] + * : Whether to persist the connection + * + * ## EXAMPLES + * terminus site filer --site=test + * + * @subcommand filer + * @alias file */ - public function filer($site_env, $options = ['app' => NULL, 'bundle' => NULL, 'persistant' => false, 'app_args' => NULL]) { + public function filer($args, $assoc_args) { + $site = $this->sites->get( + $this->input()->siteName(array('args' => $assoc_args)) + ); + $supported_apps = unserialize(SUPPORTED_APPS); $app = ''; - if (isset($options['app'])) { - $app = $options['app']; + if (isset($assoc_args['a'])) { + $app = $assoc_args['a']; } if (!in_array($app, $supported_apps)) { - $this->log()->warning('App not tested.'); + $this->failure('App not supported.'); } + $supported_bundles = array( '', 'com.panic.transmit', 'ch.sudo.cyberduck', ); $bundle = ''; - if (isset($options['bundle'])) { - $bundle = $options['bundle']; + if (isset($assoc_args['b'])) { + $bundle = $assoc_args['b']; } - if (!in_array($bundle, $supported_bundles)) { - $this->log()->warning('Bundle currently not tested.'); - } - - if(!isset($options['bundle']) && !isset($options['app'])){ - $this->log()->error('--app or --bundle flag is required'); - die; + $this->failure('Bundle not supported.'); } $persist = false; - if (isset($options['persistant'])) { - $persist = $options['persistant']; + if (isset($assoc_args['p'])) { + $persist = $assoc_args['p']; } $app_args = ''; - if (isset($options['app_args'])) { - $app_args = $options['app_args']; + if (isset($assoc_args['app_args'])) { + $app_args = $assoc_args['app_args']; } $type = 'b'; @@ -138,14 +153,15 @@ public function filer($site_env, $options = ['app' => NULL, 'bundle' => NULL, 'p } else { $app = $bundle; } - - list($site, $env) = $this->getSiteEnv($site_env); - $connection_info = $env->sftpConnectionInfo(); - $domain = $env->id . '-' . $site->get('name') . '.pantheon.io'; + + $env = $this->input()->env(array('args' => $assoc_args, 'site' => $site)); + $environment = $site->environments->get($env); + $connection_info = $environment->connectionInfo(); + $domain = $env . '-' . $site->get('name') . '.pantheon.io'; if ($persist) { // Additional connection information - $id = substr(md5($domain), 0, 8) . '-' . $site->id; + $id = substr(md5($domain), 0, 8) . '-' . $site->get('id'); $connection_info['id'] = $id; $connection_info['domain'] = $domain; $connection_info['timestamp'] = time(); @@ -157,8 +173,7 @@ public function filer($site_env, $options = ['app' => NULL, 'bundle' => NULL, 'p . '\\AppData\\Roaming\\Cyberduck\\Bookmarks\\' . $id . '.duck'; break; default: - $this->log()->error('Operating system not supported.'); - die; + $this->failure('Operating system not supported.'); } $bookmark_xml = $this->getBookmarkXml($connection_info); if ($this->writeXml($bookmark_file, $bookmark_xml)) { @@ -166,7 +181,7 @@ public function filer($site_env, $options = ['app' => NULL, 'bundle' => NULL, 'p } } } else { - $connection = $connection_info['url']; + $connection = $connection_info['sftp_url']; } // Operating system specific checks @@ -189,11 +204,16 @@ public function filer($site_env, $options = ['app' => NULL, 'bundle' => NULL, 'p break; } - $this->log()->notice( + $this->log()->info( 'Opening {domain} in {app}', array('domain' => $domain, 'app' => $app) ); - if ($this->validCommand($app)){ + // Wake the Site + $environment->wake(); + + // Open the Site in app/bundle + $this->log()->info($command); + if ($this->validCommand($app)) { exec($command); } } @@ -201,54 +221,57 @@ public function filer($site_env, $options = ['app' => NULL, 'bundle' => NULL, 'p /** * Opens the Site using Transmit SFTP Client * - * @authorize + * ## OPTIONS + * + * [--site=] + * : Site to Use * - * @command site:filer:transmit - * @aliases site:filer:panic site:transmit site:panic + * [--env=] + * : Environment * - * @param string $site_env Site & environment in the format `site-name.env` + * ## EXAMPLES + * terminus site transmit --site=test * - * @usage terminus site:filer:transmit . - * @usage terminus site:filer:panic . - * @usage terminus site:transmit . - * @usage terminus site:panic . + * @subcommand transmit + * @alias panic */ - public function transmit($site_env) { + public function transmit($args, $assoc_args) { if (OS != 'DAR') { - $this->log()->error('Operating system not supported.'); - die; + $this->failure('Operating system not supported.'); } - $this->filer($site_env, ['bundle' => 'com.panic.transmit']); + $assoc_args['b'] = 'com.panic.transmit'; + $this->filer($args, $assoc_args); } /** * Opens the Site using Cyberduck SFTP Client * - * @authorize + * ## OPTIONS + * + * [--site=] + * : Site to Use * - * @command site:filer:cyberduck - * @aliases site:filer:duck site:cyberduck site:duck + * [--env=] + * : Environment * - * @param string $site_env Site & environment in the format `site-name.env` + * ## EXAMPLES + * terminus site cyberduck --site=test * - * @usage terminus site:filer:cyberduck . - * @usage terminus site:filer:duck . - * @usage terminus site:cyberduck . - * @usage terminus site:duck . + * @subcommand cyberduck + * @alias duck */ public function cyberduck($args, $assoc_args) { switch (OS) { case 'DAR': - $assoc_args['bundle'] = 'ch.sudo.cyberduck'; + $assoc_args['b'] = 'ch.sudo.cyberduck'; break; case 'WIN': - $assoc_args['app'] = CYBERDUCK; - $assoc_args['persistant'] = true; + $assoc_args['a'] = CYBERDUCK; + $assoc_args['p'] = true; break; case 'LIN': default: - $this->log()->error('Operating system not supported.'); - die; + $this->failure('Operating system not supported.'); } $this->filer($args, $assoc_args); } @@ -256,20 +279,22 @@ public function cyberduck($args, $assoc_args) { /** * Opens the Site using FileZilla SFTP Client * - * @authorize + * ## OPTIONS + * + * [--site=] + * : Site to Use * - * @command site:filer:filezilla - * @aliases site:filer:zilla site:filezilla site:zilla + * [--env=] + * : Environment * - * @param string $site_env Site & environment in the format `site-name.env` + * ## EXAMPLES + * terminus site filezilla --site=test * - * @usage terminus site:filer:filezilla . - * @usage terminus site:filer:zilla . - * @usage terminus site:filezilla . - * @usage terminus site:zilla . + * @subcommand filezilla + * @alias zilla */ public function filezilla($args, $assoc_args) { - $assoc_args['app'] = FILEZILLA; + $assoc_args['a'] = FILEZILLA; $assoc_args['app_args'] = '-l ask'; $this->filer($args, $assoc_args); } @@ -277,24 +302,25 @@ public function filezilla($args, $assoc_args) { /** * Opens the Site using BitKinex SFTP Client * - * @authorize + * ## OPTIONS * - * @command site:filer:bitkinex - * @aliases site:filer:bit site:bitkinex site:bit + * [--site=] + * : Site to Use * - * @param string $site_env Site & environment in the format `site-name.env` + * [--env=] + * : Environment * - * @usage terminus site:filer:bitkinex . - * @usage terminus site:filer:bit . - * @usage terminus site:bitkinex . - * @usage terminus site:bit . + * ## EXAMPLES + * terminus site bitkinex --site=test + * + * @subcommand bitkinex + * @alias bit */ public function bitkinex($args, $assoc_args) { - if (!defined(PHP_WINDOWS_VERSION_MAJOR)) { - $this->log()->error('Operating system not supported.'); - die; + if (!Utils\isWindows()) { + $this->failure('Operating system not supported.'); } - $assoc_args['app'] = BITKINEX; + $assoc_args['a'] = BITKINEX; $assoc_args['app_args'] = 'browse'; $this->filer($args, $assoc_args); } @@ -302,24 +328,25 @@ public function bitkinex($args, $assoc_args) { /** * Opens the Site using WinSCP SFTP Client * - * @authorize + * ## OPTIONS + * + * [--site=] + * : Site to Use * - * @command site:filer:winscp - * @aliases site:filer:scp site:winscp site:scp + * [--env=] + * : Environment * - * @param string $site_env Site & environment in the format `site-name.env` + * ## EXAMPLES + * terminus site winscp --site=test * - * @usage terminus site:filer:winscp . - * @usage terminus site:filer:scp . - * @usage terminus site:winscp . - * @usage terminus site:scp . + * @subcommand winscp + * @alias scp */ public function winscp($args, $assoc_args) { - if (!defined(PHP_WINDOWS_VERSION_MAJOR)) { - $this->log()->error('Operating system not supported.'); - die; + if (!Utils\isWindows()) { + $this->failure('Operating system not supported.'); } - $assoc_args['app'] = WINSCP; + $assoc_args['a'] = WINSCP; $this->filer($args, $assoc_args); } @@ -342,11 +369,11 @@ private function getBookmarkXml($ci) { UUID {$ci['id']} Hostname - {$ci['host']} + {$ci['sftp_host']} Port - {$ci['port']} + {$ci['git_port']} Username - {$ci['username']} + {$ci['sftp_username']} Path Access Timestamp @@ -369,8 +396,8 @@ private function writeXml($file, $data) { fwrite($handle, $data); fclose($handle); } catch (Exception $e) { - $this->log()->error($e->getMessage()); - die; + $this->failure($e->getMessage()); + return false; } return true; } @@ -388,11 +415,9 @@ private function validCommand($file = '') { switch (OS) { case 'DAR': switch ($file) { - case 'Cyberduck': case 'ch.sudo.cyberduck': $file = '/Applications/Cyberduck.app/Contents/MacOS/Cyberduck'; break; - case 'Transmit': case 'com.panic.transmit': $file = '/Applications/Transmit.app/Contents/MacOS/Transmit'; break; @@ -410,8 +435,7 @@ private function validCommand($file = '') { } exec("ls $file", $output); if (empty($output)) { - $this->log()->error("$file does not exist."); - die; + $this->failure("$file does not exist."); return false; } return true; diff --git a/README.md b/README.md index b92017c..aa38638 100644 --- a/README.md +++ b/README.md @@ -18,38 +18,38 @@ Adds a sub-command to 'site' which is called 'filer'. This opens a site in your ## Examples ### Reference Application Name -`$ terminus site:filer companysite-33.dev --app=transmit` +`$ terminus site filer --site=companysite-33 --env=dev --a=transmit` ### Reference Application Bundle Name -`$ terminus site:filer companysite-33.dev --bundle=com.panic.transmit` +`$ terminus site filer --site=companysite-33 --env=dev --b=com.panic.transmit` ### Shortcut for Panic's Transmit -`$ terminus site:transmit companysite-33.dev` +`$ terminus site transmit --site=companysite-33 --env=dev` -`$ terminus site:panic companysite-33.dev` +`$ terminus site panic --site=companysite-33 --env=dev` ### Shortcut for Cyberduck -`$ terminus site:cyberduck companysite-33.dev` +`$ terminus site cyberduck --site=companysite-33 --env=dev` -`$ terminus site:duck companysite-33.dev` +`$ terminus site duck --site=companysite-33 --env=dev` ### Shortcut for FileZilla -`$ terminus site:filezilla companysite-33.dev` +`$ terminus site filezilla --site=companysite-33 --env=dev` -`$ terminus site:zilla companysite-33.dev` +`$ terminus site zilla --site=companysite-33 --env=dev` ### Shortcut for BitKinex -`$ terminus site:bitkinex companysite-33.dev` +`$ terminus site bitkinex --site=companysite-33 --env=dev` -`$ terminus site:bit companysite-33.dev` +`$ terminus site bit --site=companysite-33 --env=dev` ### Shortcut for WinSCP -`$ terminus site:winscp companysite-33.dev` +`$ terminus site winscp --site=companysite-33 --env=dev` -`$ terminus site:scp companysite-33.dev` +`$ terminus site scp --site=companysite-33 --env=dev` ## Installation -For help installing, see [Terminus's Plugins](https://pantheon.io/docs/terminus/plugins/). +For help installing, see [Terminus's Wiki](https://github.com/pantheon-systems/terminus/wiki/Plugins). ## Windows @@ -71,5 +71,4 @@ Example: `TEMINUS_FILER_BITKINEX_LOC="C:\BitKinex\bitkinex.exe"` See http://www.computerhope.com/issues/ch000549.htm for information on how to set environment variables in Windows. ## Help -Run `terminus help site:filer` for help. - +Run `terminus help site filer` for help. diff --git a/composer.json b/composer.json index fdfe6d2..11e522c 100644 --- a/composer.json +++ b/composer.json @@ -1,18 +1,9 @@ { - "name": "terminus-plugin-project/terminus-filer-plugin", + "name": "sean-e-dietrich/terminus-filer", "description": "Filer - A Terminus plugin for SFTP Connections", - "homepage": "https://github.com/terminus-plugin-project/terminus-filer", + "homepage": "https://github.com/sean-e-dietrich/terminus-filer", "license": "MIT", - "type": "terminus-plugin", "require": { "php": ">=5.4" - }, - "autoload": { - "psr-4": { "Pantheon\\TerminusFiler\\": "src" } - }, - "extra": { - "terminus": { - "compatible-version": "^1" - } } }