array( 'param' => 'branch_name', 'help' => "Select branch name to view (on server). Defaults to 'master'." ), '*' => 'paths', ); } public function requiresWorkingCopy() { return true; } public function requiresConduit() { return true; } public function requiresAuthentication() { return true; } public function requiresRepositoryAPI() { return true; } public function run() { $repository_api = $this->getRepositoryAPI(); $project_root = $this->getWorkingCopy()->getProjectRoot(); $in_paths = $this->getArgument('paths'); $paths = array(); foreach ($in_paths as $key => $path) { $path = preg_replace('/:([0-9]+)$/', '$\1', $path); $full_path = Filesystem::resolvePath($path); if ($full_path == $project_root) { $paths[$key] = ''; } else { $paths[$key] = Filesystem::readablePath($full_path, $project_root); } } if (!$paths) { throw new ArcanistUsageException("Specify a path to browse."); } $base_uri = $this->getBaseURI(); $browser = $this->getBrowserCommand(); foreach ($paths as $path) { $ret_code = phutil_passthru("%s %s", $browser, $base_uri . $path); if ($ret_code) { throw new ArcanistUsageException( "It seems we failed to open the browser; perhaps you should try to ". "set the 'browser' config option. The command we tried to use was: ". $browser); } } return 0; } private function getBaseURI() { $repo_uri = $this->getRepositoryURI(); $branch = $this->getArgument('branch', 'master'); return $repo_uri.'browse/'.$branch.'/'; } private function getBrowserCommand() { $config = $this->getConfigFromAnySource('browser'); if ($config) { return $config; } if (phutil_is_windows()) { return "start"; } $candidates = array("sensible-browser", "xdg-open", "open"); // on many Linuxes, "open" exists and is not the right program. foreach ($candidates as $cmd) { list($ret_code) = exec_manual("which %s", $cmd); if ($ret_code == 0) { return $cmd; } } throw new ArcanistUsageException( "Could not find a browser to run; Try setting the 'browser' option " . "using arc set-config."); } }