$workflows = id(new PhutilSymbolLoader())->setAncestorClass('PhabricatorSSHWorkflow')->loadObjects();
 $workflow_names = mpull($workflows, 'getName', 'getName');
 if (!$original_argv) {
     throw new Exception(pht("Welcome to Phabricator.\n\n" . "You are logged in as %s.\n\n" . "You haven't specified a command to run. This means you're requesting " . "an interactive shell, but Phabricator does not provide an " . "interactive shell over SSH.\n\n" . "Usually, you should run a command like `%s` or `%s` " . "rather than connecting directly with SSH.\n\n" . "Supported commands are: %s.", $user->getUsername(), 'git clone', 'hg push', implode(', ', $workflow_names)));
 }
 $log_argv = implode(' ', $original_argv);
 $log_argv = id(new PhutilUTF8StringTruncator())->setMaximumCodepoints(128)->truncateString($log_argv);
 $ssh_log->setData(array('C' => $original_argv[0], 'U' => $log_argv));
 $command = head($original_argv);
 $parseable_argv = $original_argv;
 array_unshift($parseable_argv, 'phabricator-ssh-exec');
 $parsed_args = new PhutilArgumentParser($parseable_argv);
 if (empty($workflow_names[$command])) {
     throw new Exception(pht('Invalid command.'));
 }
 $workflow = $parsed_args->parseWorkflows($workflows);
 $workflow->setUser($user);
 $workflow->setOriginalArguments($original_argv);
 $workflow->setIsClusterRequest($is_cluster_request);
 $sock_stdin = fopen('php://stdin', 'r');
 if (!$sock_stdin) {
     throw new Exception(pht('Unable to open stdin.'));
 }
 $sock_stdout = fopen('php://stdout', 'w');
 if (!$sock_stdout) {
     throw new Exception(pht('Unable to open stdout.'));
 }
 $sock_stderr = fopen('php://stderr', 'w');
 if (!$sock_stderr) {
     throw new Exception(pht('Unable to open stderr.'));
 }
#!/usr/bin/env php
<?php 
$root = dirname(dirname(dirname(__FILE__)));
require_once $root . '/scripts/__init_script__.php';
$args = new PhutilArgumentParser($argv);
$args->setTagline('manage celerity');
$args->setSynopsis(<<<EOSYNOPSIS
**celerity** __command__ [__options__]
    Manage static resources.

EOSYNOPSIS
);
$args->parseStandardArguments();
$workflows = id(new PhutilSymbolLoader())->setAncestorClass('CelerityManagementWorkflow')->loadObjects();
$workflows[] = new PhutilHelpArgumentWorkflow();
$args->parseWorkflows($workflows);
Exemple #3
0
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
require_once dirname(dirname(__FILE__)) . '/__init_script__.php';
$args = new PhutilArgumentParser($argv);
$args->setTagline('simple calculator example');
$args->setSynopsis(<<<EOHELP
**calculator.php** __op__ __n__ ...
Perform a calculation.
EOHELP
);
$add_workflow = id(new PhutilArgumentWorkflow())->setName('add')->setExamples('**add** __n__ ...')->setSynopsis('Compute the sum of a list of numbers.')->setArguments(array(array('name' => 'numbers', 'wildcard' => true)));
$mul_workflow = id(new PhutilArgumentWorkflow())->setName('mul')->setExamples('**mul** __n__ ...')->setSynopsis('Compute the product of a list of numbers.')->setArguments(array(array('name' => 'numbers', 'wildcard' => true)));
$flow = $args->parseWorkflows(array($add_workflow, $mul_workflow, new PhutilHelpArgumentWorkflow()));
$nums = $args->getArg('numbers');
if (empty($nums)) {
    echo "You must provide one or more numbers!\n";
    exit(1);
}
foreach ($nums as $num) {
    if (!is_numeric($num)) {
        echo "Number '{$num}' is not numeric!\n";
        exit(1);
    }
}
switch ($flow->getName()) {
    case 'add':
        echo array_sum($nums) . "\n";
        break;
 public function execute(PhutilArgumentParser $args)
 {
     $echo_workflow = id(new PhutilEchoExampleArgumentWorkflow())->setName('echo')->setExamples('**echo** __string__ ...')->setSynopsis(pht('Echo __string__.'));
     $args->parseWorkflows(array($echo_workflow, new PhutilHelpArgumentWorkflow()));
 }
Exemple #5
0
 $workflow_names = mpull($workflows, 'getName', 'getName');
 // Now, rebuild the original command.
 $original_argv = id(new PhutilShellLexer())->splitArguments($original_command);
 if (!$original_argv) {
     throw new Exception(pht("Welcome to Phabricator.\n\n" . "You are logged in as %s.\n\n" . "You haven't specified a command to run. This means you're requesting " . "an interactive shell, but Phabricator does not provide an " . "interactive shell over SSH.\n\n" . "Usually, you should run a command like `git clone` or `hg push` " . "rather than connecting directly with SSH.\n\n" . "Supported commands are: %s.", $user->getUsername(), implode(', ', $workflow_names)));
 }
 $log_argv = implode(' ', array_slice($original_argv, 1));
 $log_argv = id(new PhutilUTF8StringTruncator())->setMaximumCodepoints(128)->truncateString($log_argv);
 $ssh_log->setData(array('C' => $original_argv[0], 'U' => $log_argv));
 $command = head($original_argv);
 array_unshift($original_argv, 'phabricator-ssh-exec');
 $original_args = new PhutilArgumentParser($original_argv);
 if (empty($workflow_names[$command])) {
     throw new Exception('Invalid command.');
 }
 $workflow = $original_args->parseWorkflows($workflows);
 $workflow->setUser($user);
 $sock_stdin = fopen('php://stdin', 'r');
 if (!$sock_stdin) {
     throw new Exception('Unable to open stdin.');
 }
 $sock_stdout = fopen('php://stdout', 'w');
 if (!$sock_stdout) {
     throw new Exception('Unable to open stdout.');
 }
 $sock_stderr = fopen('php://stderr', 'w');
 if (!$sock_stderr) {
     throw new Exception('Unable to open stderr.');
 }
 $socket_channel = new PhutilSocketChannel($sock_stdin, $sock_stdout);
 $error_channel = new PhutilSocketChannel(null, $sock_stderr);