2012-12-09 23:09:35 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2014-02-09 21:19:57 +01:00
|
|
|
* Browse files in the Diffusion web interface.
|
2012-12-09 23:09:35 +01:00
|
|
|
*/
|
2014-07-21 23:49:15 +02:00
|
|
|
final class ArcanistBrowseWorkflow extends ArcanistWorkflow {
|
2012-12-09 23:09:35 +01:00
|
|
|
|
|
|
|
public function getWorkflowName() {
|
|
|
|
return 'browse';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCommandSynopses() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
2014-02-09 21:19:57 +01:00
|
|
|
**browse** [__options__] __path__ ...
|
2012-12-09 23:09:35 +01:00
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCommandHelp() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
2014-02-09 21:19:57 +01:00
|
|
|
Supports: git, hg, svn
|
|
|
|
Browse files in the Diffusion web interface.
|
2012-12-09 23:09:35 +01:00
|
|
|
|
|
|
|
Set the 'browser' value using 'arc set-config' to select a browser. If
|
|
|
|
no browser is set, the command will try to guess which browser to use.
|
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getArguments() {
|
|
|
|
return array(
|
|
|
|
'branch' => array(
|
|
|
|
'param' => 'branch_name',
|
2014-02-09 21:19:57 +01:00
|
|
|
'help' => pht(
|
|
|
|
'Default branch name to view on server. Defaults to "master".'),
|
2012-12-09 23:09:35 +01:00
|
|
|
),
|
|
|
|
'*' => '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');
|
2014-02-09 21:19:57 +01:00
|
|
|
if (!$in_paths) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
pht(
|
|
|
|
'Specify one or more paths to browse. Use the command '.
|
|
|
|
'"arc browse ." if you want to browse this directory.'));
|
|
|
|
}
|
|
|
|
|
2012-12-09 23:09:35 +01:00
|
|
|
$paths = array();
|
|
|
|
foreach ($in_paths as $key => $path) {
|
2013-07-15 04:14:34 +02:00
|
|
|
$path = preg_replace('/:([0-9]+)$/', '$\1', $path);
|
2012-12-09 23:09:35 +01:00
|
|
|
$full_path = Filesystem::resolvePath($path);
|
|
|
|
|
2014-02-09 18:00:54 +01:00
|
|
|
if ($full_path == $project_root) {
|
|
|
|
$paths[$key] = '';
|
|
|
|
} else {
|
|
|
|
$paths[$key] = Filesystem::readablePath($full_path, $project_root);
|
|
|
|
}
|
2012-12-09 23:09:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$base_uri = $this->getBaseURI();
|
|
|
|
$browser = $this->getBrowserCommand();
|
|
|
|
|
|
|
|
foreach ($paths as $path) {
|
2014-02-09 21:19:57 +01:00
|
|
|
$ret_code = phutil_passthru('%s %s', $browser, $base_uri.$path);
|
2012-12-09 23:09:35 +01:00
|
|
|
if ($ret_code) {
|
|
|
|
throw new ArcanistUsageException(
|
2013-07-15 04:14:34 +02:00
|
|
|
"It seems we failed to open the browser; perhaps you should try to ".
|
2012-12-09 23:09:35 +01:00
|
|
|
"set the 'browser' config option. The command we tried to use was: ".
|
|
|
|
$browser);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getBaseURI() {
|
2014-02-09 17:55:16 +01:00
|
|
|
$repo_uri = $this->getRepositoryURI();
|
2014-02-09 21:19:57 +01:00
|
|
|
if ($repo_uri === null) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
pht(
|
|
|
|
'arc is unable to determine which repository in Diffusion '.
|
|
|
|
'this working copy belongs to. Use "arc which" to understand how '.
|
|
|
|
'arc looks for a repository.'));
|
|
|
|
}
|
|
|
|
|
2012-12-09 23:09:35 +01:00
|
|
|
$branch = $this->getArgument('branch', 'master');
|
|
|
|
|
2014-02-09 17:55:16 +01:00
|
|
|
return $repo_uri.'browse/'.$branch.'/';
|
2012-12-09 23:09:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function getBrowserCommand() {
|
2013-10-19 01:10:06 +02:00
|
|
|
$config = $this->getConfigFromAnySource('browser');
|
2012-12-09 23:09:35 +01:00
|
|
|
if ($config) {
|
|
|
|
return $config;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (phutil_is_windows()) {
|
2014-02-09 21:19:57 +01:00
|
|
|
return 'start';
|
2012-12-09 23:09:35 +01:00
|
|
|
}
|
|
|
|
|
2014-02-09 21:19:57 +01:00
|
|
|
$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.
|
2012-12-09 23:09:35 +01:00
|
|
|
|
|
|
|
foreach ($candidates as $cmd) {
|
2014-02-09 21:19:57 +01:00
|
|
|
if (Filesystem::binaryExists($cmd)) {
|
2012-12-09 23:09:35 +01:00
|
|
|
return $cmd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new ArcanistUsageException(
|
2014-02-09 21:19:57 +01:00
|
|
|
pht(
|
|
|
|
"Unable to find a browser command to run. Set 'browser' in your ".
|
|
|
|
"arc config to specify one."));
|
2012-12-09 23:09:35 +01:00
|
|
|
}
|
2014-07-09 01:12:13 +02:00
|
|
|
|
2012-12-09 23:09:35 +01:00
|
|
|
}
|