1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-12-23 22:10:54 +01:00

Add a --browse flag to arc diff, to open objects in a browser after creating them

Summary: Ref T5781. Add a flag to optionally open a web browser after creating a diff or revision.

Test Plan: Created //this revision// with `arc diff --browse` // !!! //

Reviewers: csilvers, btrahan

Reviewed By: btrahan

Subscribers: epriestley, spicyj

Maniphest Tasks: T5781

Differential Revision: https://secure.phabricator.com/D10141
This commit is contained in:
epriestley 2014-08-04 12:03:03 -07:00
parent 2e6d11c18a
commit 72447f649f
3 changed files with 61 additions and 39 deletions

View file

@ -144,16 +144,7 @@ EOTEXT
}
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 @@ EOTEXT
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."));
}
}

View file

@ -392,6 +392,10 @@ EOTEXT
'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 @@ EOTEXT
))."\n";
ob_start();
}
if ($this->shouldOpenCreatedObjectsInBrowser()) {
$this->openURIsInBrowser(array($diff_info['uri']));
}
} else {
$revision['diffid'] = $this->getDiffID();
@ -626,6 +634,10 @@ EOTEXT
));
echo "Planned changes to the revision.\n";
}
if ($this->shouldOpenCreatedObjectsInBrowser()) {
$this->openURIsInBrowser(array($uri));
}
}
echo "Included changes:\n";
@ -2623,4 +2635,8 @@ EOTEXT
return Filesystem::getMimeType($tmp);
}
private function shouldOpenCreatedObjectsInBrowser() {
return $this->getArgument('browse');
}
}

View file

@ -1795,4 +1795,48 @@ abstract class ArcanistWorkflow extends Phobject {
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."));
}
}