diff --git a/src/workflow/ArcanistBrowseWorkflow.php b/src/workflow/ArcanistBrowseWorkflow.php --- a/src/workflow/ArcanistBrowseWorkflow.php +++ b/src/workflow/ArcanistBrowseWorkflow.php @@ -144,16 +144,7 @@ } if ($uris) { - $browser = $this->getBrowserCommand(); - foreach ($uris as $uri) { - $err = phutil_passthru('%s %s', $browser, $uri); - if ($err) { - throw new ArcanistUsageException( - pht( - "Failed to execute browser ('%s'). Check your 'browser' config ". - "option.")); - } - } + $this->openURIsInBrowser($uris); } return 0; @@ -174,33 +165,4 @@ 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'); - - // NOTE: The "open" command works well on OS X, but on many Linuxes "open" - // exists and is not a browser. For now, we're just looking for other - // commands first, but we might want to be smarter about selecting "open" - // only on OS X. - - foreach ($candidates as $cmd) { - if (Filesystem::binaryExists($cmd)) { - return $cmd; - } - } - - throw new ArcanistUsageException( - pht( - "Unable to find a browser command to run. Set 'browser' in your ". - "arc config to specify one.")); - } - } diff --git a/src/workflow/ArcanistDiffWorkflow.php b/src/workflow/ArcanistDiffWorkflow.php --- a/src/workflow/ArcanistDiffWorkflow.php +++ b/src/workflow/ArcanistDiffWorkflow.php @@ -392,6 +392,10 @@ 'unit' => true, ), ), + 'browse' => array( + 'help' => pht( + 'After creating a diff or revision, open it in a web browser.'), + ), '*' => 'paths', 'head' => array( 'param' => 'commit', @@ -570,6 +574,10 @@ ))."\n"; ob_start(); } + + if ($this->shouldOpenCreatedObjectsInBrowser()) { + $this->openURIsInBrowser(array($diff_info['uri'])); + } } else { $revision['diffid'] = $this->getDiffID(); @@ -626,6 +634,10 @@ )); echo "Planned changes to the revision.\n"; } + + if ($this->shouldOpenCreatedObjectsInBrowser()) { + $this->openURIsInBrowser(array($uri)); + } } echo "Included changes:\n"; @@ -2623,4 +2635,8 @@ return Filesystem::getMimeType($tmp); } + private function shouldOpenCreatedObjectsInBrowser() { + return $this->getArgument('browse'); + } + } diff --git a/src/workflow/ArcanistWorkflow.php b/src/workflow/ArcanistWorkflow.php --- a/src/workflow/ArcanistWorkflow.php +++ b/src/workflow/ArcanistWorkflow.php @@ -1795,4 +1795,48 @@ return $engine; } + protected function openURIsInBrowser(array $uris) { + $browser = $this->getBrowserCommand(); + foreach ($uris as $uri) { + $err = phutil_passthru('%s %s', $browser, $uri); + if ($err) { + throw new ArcanistUsageException( + pht( + "Failed to open '%s' in browser ('%s'). ". + "Check your 'browser' config option.", + $uri, + $browser)); + } + } + } + + private function getBrowserCommand() { + $config = $this->getConfigFromAnySource('browser'); + if ($config) { + return $config; + } + + if (phutil_is_windows()) { + return 'start'; + } + + $candidates = array('sensible-browser', 'xdg-open', 'open'); + + // NOTE: The "open" command works well on OS X, but on many Linuxes "open" + // exists and is not a browser. For now, we're just looking for other + // commands first, but we might want to be smarter about selecting "open" + // only on OS X. + + foreach ($candidates as $cmd) { + if (Filesystem::binaryExists($cmd)) { + return $cmd; + } + } + + throw new ArcanistUsageException( + pht( + "Unable to find a browser command to run. Set 'browser' in your ". + "Arcanist config to specify a command to use.")); + } + }