From 92febf184eafbad6665d9a23a91289fcc62a51cc Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 8 Mar 2012 12:20:26 -0800 Subject: [PATCH] Use PhutilArgumentParser for some argument parsing in Arcanist Summary: Instead of doing custom parsing for --trace and --no-ansi, use builtin parsing. This also gives us access to xprofile. I eventually want to fully switch over, but that'll take some work. Test Plan: Ran `arc list --trace`, `arc list --no-ansi`, etc. Reviewers: btrahan Reviewed By: btrahan CC: aran, epriestley Differential Revision: https://secure.phabricator.com/D1827 --- scripts/arcanist.php | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/scripts/arcanist.php b/scripts/arcanist.php index 59d3665d..352e476f 100755 --- a/scripts/arcanist.php +++ b/scripts/arcanist.php @@ -34,20 +34,20 @@ phutil_require_module('arcanist', 'repository/api/base'); ini_set('memory_limit', -1); -$config_trace_mode = false; +$original_argv = $argv; +$args = new PhutilArgumentParser($argv); +$args->parseStandardArguments(); + +$argv = $args->getUnconsumedArgumentVector(); +$config_trace_mode = $args->getArg('trace'); + $force_conduit = null; -$args = array_slice($argv, 1); +$args = $argv; $load = array(); $matches = null; foreach ($args as $key => $arg) { if ($arg == '--') { break; - } else if ($arg == '--trace') { - unset($args[$key]); - $config_trace_mode = true; - } else if ($arg == '--no-ansi') { - unset($args[$key]); - PhutilConsoleFormatter::disableANSI(true); } else if (preg_match('/^--load-phutil-library=(.*)$/', $arg, $matches)) { unset($args[$key]); $load[] = $matches[1]; @@ -57,20 +57,11 @@ foreach ($args as $key => $arg) { } } -// The POSIX extension is not available by default in some PHP installs. -if (function_exists('posix_isatty') && !posix_isatty(STDOUT)) { - PhutilConsoleFormatter::disableANSI(true); -} - $args = array_values($args); $working_directory = getcwd(); try { - if ($config_trace_mode) { - PhutilServiceProfiler::installEchoListener(); - } - if (!$args) { throw new ArcanistUsageException("No command provided. Try 'arc help'."); } @@ -252,7 +243,7 @@ try { $user_name = idx($host_config, 'user'); $certificate = idx($host_config, 'cert'); - $description = implode(' ', $argv); + $description = implode(' ', $original_argv); $credentials = array( 'user' => $user_name, 'certificate' => $certificate,