mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 14:52:40 +01:00
Allow "arc browse" to browse objects
Summary: Ref T5781. This implements `arc browse T234`, for any monogrammed object. Test Plan: - Ran `arc browse T234` outside of a working copy (does not require repository API). - Ran `arc browse T234` in a working copy, got task. - Ran `arc browse PATH` in a working copy. - Ran `arc browse nonpath` with and without `--force`. Reviewers: csilvers, btrahan Reviewed By: btrahan Subscribers: epriestley, spicyj Maniphest Tasks: T5781 Differential Revision: https://secure.phabricator.com/D10140
This commit is contained in:
parent
bb6d11b732
commit
2e6d11c18a
1 changed files with 91 additions and 26 deletions
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Browse files in the Diffusion web interface.
|
* Browse files or objects in the Phabricator web interface.
|
||||||
*/
|
*/
|
||||||
final class ArcanistBrowseWorkflow extends ArcanistWorkflow {
|
final class ArcanistBrowseWorkflow extends ArcanistWorkflow {
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ final class ArcanistBrowseWorkflow extends ArcanistWorkflow {
|
||||||
public function getCommandSynopses() {
|
public function getCommandSynopses() {
|
||||||
return phutil_console_format(<<<EOTEXT
|
return phutil_console_format(<<<EOTEXT
|
||||||
**browse** [__options__] __path__ ...
|
**browse** [__options__] __path__ ...
|
||||||
|
**browse** [__options__] __object__ ...
|
||||||
EOTEXT
|
EOTEXT
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -19,7 +20,10 @@ EOTEXT
|
||||||
public function getCommandHelp() {
|
public function getCommandHelp() {
|
||||||
return phutil_console_format(<<<EOTEXT
|
return phutil_console_format(<<<EOTEXT
|
||||||
Supports: git, hg, svn
|
Supports: git, hg, svn
|
||||||
Browse files in the Diffusion web interface.
|
Open a file or object (like a task or revision) in your web browser.
|
||||||
|
|
||||||
|
$ arc browse README # Open a file in Diffusion.
|
||||||
|
$ arc browse T123 # View a task.
|
||||||
|
|
||||||
Set the 'browser' value using 'arc set-config' to select a browser. If
|
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.
|
no browser is set, the command will try to guess which browser to use.
|
||||||
|
@ -34,11 +38,16 @@ EOTEXT
|
||||||
'help' => pht(
|
'help' => pht(
|
||||||
'Default branch name to view on server. Defaults to "master".'),
|
'Default branch name to view on server. Defaults to "master".'),
|
||||||
),
|
),
|
||||||
|
'force' => array(
|
||||||
|
'help' => pht(
|
||||||
|
'Open arguments as paths, even if they do not exist in the '.
|
||||||
|
'working copy.'),
|
||||||
|
),
|
||||||
'*' => 'paths',
|
'*' => 'paths',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function requiresWorkingCopy() {
|
public function desiresWorkingCopy() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,44 +59,100 @@ EOTEXT
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function requiresRepositoryAPI() {
|
public function desiresRepositoryAPI() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run() {
|
public function run() {
|
||||||
$repository_api = $this->getRepositoryAPI();
|
$console = PhutilConsole::getConsole();
|
||||||
$project_root = $this->getWorkingCopy()->getProjectRoot();
|
|
||||||
|
|
||||||
$in_paths = $this->getArgument('paths');
|
$is_force = $this->getArgument('force');
|
||||||
if (!$in_paths) {
|
|
||||||
|
$things = $this->getArgument('paths');
|
||||||
|
if (!$things) {
|
||||||
throw new ArcanistUsageException(
|
throw new ArcanistUsageException(
|
||||||
pht(
|
pht(
|
||||||
'Specify one or more paths to browse. Use the command '.
|
'Specify one or more paths or objects to browse. Use the command '.
|
||||||
'"arc browse ." if you want to browse this directory.'));
|
'"arc browse ." if you want to browse this directory.'));
|
||||||
}
|
}
|
||||||
|
$things = array_fuse($things);
|
||||||
|
|
||||||
$paths = array();
|
$objects = $this->getConduit()->callMethodSynchronous(
|
||||||
foreach ($in_paths as $key => $path) {
|
'phid.lookup',
|
||||||
$path = preg_replace('/:([0-9]+)$/', '$\1', $path);
|
array(
|
||||||
$full_path = Filesystem::resolvePath($path);
|
'names' => array_keys($things),
|
||||||
|
));
|
||||||
|
|
||||||
if ($full_path == $project_root) {
|
$uris = array();
|
||||||
$paths[$key] = '';
|
foreach ($objects as $name => $object) {
|
||||||
} else {
|
$uris[] = $object['uri'];
|
||||||
$paths[$key] = Filesystem::readablePath($full_path, $project_root);
|
|
||||||
|
$console->writeOut(
|
||||||
|
pht(
|
||||||
|
'Opening **%s** as an object.',
|
||||||
|
$name)."\n");
|
||||||
|
|
||||||
|
unset($things[$name]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->hasRepositoryAPI()) {
|
||||||
|
$repository_api = $this->getRepositoryAPI();
|
||||||
|
$project_root = $this->getWorkingCopy()->getProjectRoot();
|
||||||
|
|
||||||
|
foreach ($things as $key => $path) {
|
||||||
|
$path = preg_replace('/:([0-9]+)$/', '$\1', $path);
|
||||||
|
$full_path = Filesystem::resolvePath($path);
|
||||||
|
|
||||||
|
if (!$is_force && !Filesystem::pathExists($full_path)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$console->writeOut(
|
||||||
|
pht(
|
||||||
|
'Opening **%s** as a repository path.',
|
||||||
|
$key)."\n");
|
||||||
|
|
||||||
|
unset($things[$key]);
|
||||||
|
|
||||||
|
if ($full_path == $project_root) {
|
||||||
|
$path = '';
|
||||||
|
} else {
|
||||||
|
$path = Filesystem::readablePath($full_path, $project_root);
|
||||||
|
}
|
||||||
|
|
||||||
|
$base_uri = $this->getBaseURI();
|
||||||
|
$uris[] = $base_uri.$path;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ($things) {
|
||||||
|
$console->writeOut(
|
||||||
|
pht(
|
||||||
|
"The current working directory is not a repository working ".
|
||||||
|
"copy, so remaining arguments can not be resolved as paths. ".
|
||||||
|
"To browse paths in Diffusion, run 'arc browse' from inside ".
|
||||||
|
"a working copy.")."\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$base_uri = $this->getBaseURI();
|
foreach ($things as $thing) {
|
||||||
$browser = $this->getBrowserCommand();
|
$console->writeOut(
|
||||||
|
pht(
|
||||||
|
'Unable to find an object named **%s**, and no such path exists '.
|
||||||
|
'in the working copy. Use __--force__ to treat this as a path '.
|
||||||
|
'anyway.',
|
||||||
|
$thing)."\n");
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($paths as $path) {
|
if ($uris) {
|
||||||
$ret_code = phutil_passthru('%s %s', $browser, $base_uri.$path);
|
$browser = $this->getBrowserCommand();
|
||||||
if ($ret_code) {
|
foreach ($uris as $uri) {
|
||||||
throw new ArcanistUsageException(
|
$err = phutil_passthru('%s %s', $browser, $uri);
|
||||||
"It seems we failed to open the browser; perhaps you should try to ".
|
if ($err) {
|
||||||
"set the 'browser' config option. The command we tried to use was: ".
|
throw new ArcanistUsageException(
|
||||||
$browser);
|
pht(
|
||||||
|
"Failed to execute browser ('%s'). Check your 'browser' config ".
|
||||||
|
"option."));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue