From b7c827c2e5cc407496ea90e3334ad41124b93da5 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 1 May 2015 15:46:34 +0100 Subject: [PATCH] Use external lib for hidden cli prompting --- composer.json | 3 +- composer.lock | 50 +++++++++++++++++++++++- src/Composer/Compiler.php | 3 +- src/Composer/IO/ConsoleIO.php | 67 +------------------------------- src/Composer/IO/hiddeninput.exe | Bin 9216 -> 0 bytes 5 files changed, 55 insertions(+), 68 deletions(-) delete mode 100644 src/Composer/IO/hiddeninput.exe diff --git a/composer.json b/composer.json index 7d9b8b698..db660ad59 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,8 @@ "symfony/console": "~2.5", "symfony/finder": "~2.2", "symfony/process": "~2.1", - "seld/phar-utils": "~1.0" + "seld/phar-utils": "~1.0", + "seld/cli-prompt": "~1.0" }, "require-dev": { "phpunit/phpunit": "~4.5", diff --git a/composer.lock b/composer.lock index dfe996228..d15089b0f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "3b9e15f9521bb0a41897f65f76c1c7de", + "hash": "0a85d5ff8ee6c1e805ef16f2afd87238", "packages": [ { "name": "justinrainbow/json-schema", @@ -72,6 +72,54 @@ ], "time": "2015-03-27 16:41:39" }, + { + "name": "seld/cli-prompt", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/Seldaek/cli-prompt.git", + "reference": "fe114c7a6ac5cb0ce76932ae4017024d9842a49c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Seldaek/cli-prompt/zipball/fe114c7a6ac5cb0ce76932ae4017024d9842a49c", + "reference": "fe114c7a6ac5cb0ce76932ae4017024d9842a49c", + "shasum": "" + }, + "require": { + "php": ">=5.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Seld\\CliPrompt\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be" + } + ], + "description": "Allows you to prompt for user input on the command line, and optionally hide the characters they type", + "keywords": [ + "cli", + "console", + "hidden", + "input", + "prompt" + ], + "time": "2015-04-30 20:24:49" + }, { "name": "seld/jsonlint", "version": "1.3.1", diff --git a/src/Composer/Compiler.php b/src/Composer/Compiler.php index b3e4abcdc..749adf659 100644 --- a/src/Composer/Compiler.php +++ b/src/Composer/Compiler.php @@ -102,7 +102,7 @@ class Compiler foreach ($finder as $file) { $this->addFile($phar, $file, false); } - $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../src/Composer/IO/hiddeninput.exe'), false); + $this->addFile($phar, new \SplFileInfo(__DIR__ . '/../../vendor/seld/cli-prompt/res/hiddeninput.exe'), false); $finder = new Finder(); $finder->files() @@ -114,6 +114,7 @@ class Compiler ->exclude('docs') ->in(__DIR__.'/../../vendor/symfony/') ->in(__DIR__.'/../../vendor/seld/jsonlint/') + ->in(__DIR__.'/../../vendor/seld/cli-prompt/') ->in(__DIR__.'/../../vendor/justinrainbow/json-schema/') ->sort($finderSort) ; diff --git a/src/Composer/IO/ConsoleIO.php b/src/Composer/IO/ConsoleIO.php index 366c67483..622e73ccf 100644 --- a/src/Composer/IO/ConsoleIO.php +++ b/src/Composer/IO/ConsoleIO.php @@ -254,71 +254,8 @@ class ConsoleIO extends BaseIO */ public function askAndHideAnswer($question) { - // handle windows - if (defined('PHP_WINDOWS_VERSION_BUILD')) { - $finder = new ExecutableFinder(); + $this->writeError($question, false); - // use bash if it's present - if ($finder->find('bash') && $finder->find('stty')) { - $this->writeError($question, false); - $value = rtrim(shell_exec('bash -c "stty -echo; read -n0 discard; read -r mypassword; stty echo; echo $mypassword"')); - $this->writeError(''); - - return $value; - } - - // fallback to hiddeninput executable - $exe = __DIR__.'\\hiddeninput.exe'; - - // handle code running from a phar - if ('phar:' === substr(__FILE__, 0, 5)) { - $tmpExe = sys_get_temp_dir().'/hiddeninput.exe'; - - // use stream_copy_to_stream instead of copy - // to work around https://bugs.php.net/bug.php?id=64634 - $source = fopen(__DIR__.'\\hiddeninput.exe', 'r'); - $target = fopen($tmpExe, 'w+'); - stream_copy_to_stream($source, $target); - fclose($source); - fclose($target); - unset($source, $target); - - $exe = $tmpExe; - } - - $this->writeError($question, false); - $value = rtrim(shell_exec($exe)); - $this->writeError(''); - - // clean up - if (isset($tmpExe)) { - unlink($tmpExe); - } - - return $value; - } - - if (file_exists('/usr/bin/env')) { - // handle other OSs with bash/zsh/ksh/csh if available to hide the answer - $test = "/usr/bin/env %s -c 'echo OK' 2> /dev/null"; - foreach (array('bash', 'zsh', 'ksh', 'csh') as $sh) { - if ('OK' === rtrim(shell_exec(sprintf($test, $sh)))) { - $shell = $sh; - break; - } - } - if (isset($shell)) { - $this->writeError($question, false); - $readCmd = ($shell === 'csh') ? 'set mypassword = $<' : 'read -r mypassword'; - $command = sprintf("/usr/bin/env %s -c 'stty -echo; %s; stty echo; echo \$mypassword'", $shell, $readCmd); - $value = rtrim(shell_exec($command)); - $this->writeError(''); - - return $value; - } - } - - // not able to hide the answer, proceed with normal question handling - return $this->ask($question); + return \Seld\CliPrompt\CliPrompt::hiddenPrompt(true); } } diff --git a/src/Composer/IO/hiddeninput.exe b/src/Composer/IO/hiddeninput.exe deleted file mode 100644 index c8cf65e8d819e6e525121cf6b21f1c2429746038..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9216 zcmeHNe{@sVeZR8hV88~S)=Hp|Mpn({rC^@)BwNOI{ERJXCYlx+k1K6PLHo z_e!z_fhOzeA3JTX&-Z@s{rFOgjEwBlqjr!)9f zjyHz`A+ni`!0Taby{Uj5Y>jQq(k5A+X})PLWAi|{IZbtc8n^^trM{GI=P_15U6d?l zJJ3PW8XjfHpR}6`k{&5@JcEeH_SqQoQbU62o2YS30W)p_t&Fjy*RXQCZt$gCf|ao| zx&3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