mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-26 16:52:40 +01:00
Improve argument parsing for "arc patch --revision Dxxx"
Summary: See PHI527. Ref T13116. The `--revision` flag currently fails if the argument is in the form `D123` instead of `123`. Normalize monogram arguments. Test Plan: Ran `arc patch --revision Dxxx`, `arc patch --revision xxx`, `arc patch --revision xxx --diff yyy`, `arc patch`; got good behavior on the good ones and sensible error messages on the other ones. Maniphest Tasks: T13116 Differential Revision: https://secure.phabricator.com/D19292
This commit is contained in:
parent
b8c9c385a7
commit
e44a2d3ac0
1 changed files with 44 additions and 51 deletions
|
@ -115,66 +115,59 @@ EOTEXT
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function didParseArguments() {
|
protected function didParseArguments() {
|
||||||
$source = null;
|
$arguments = array(
|
||||||
$requested = 0;
|
'revision' => self::SOURCE_REVISION,
|
||||||
if ($this->getArgument('revision')) {
|
'diff' => self::SOURCE_DIFF,
|
||||||
$source = self::SOURCE_REVISION;
|
'arcbundle' => self::SOURCE_BUNDLE,
|
||||||
$requested++;
|
'patch' => self::SOURCE_PATCH,
|
||||||
}
|
'name' => self::SOURCE_REVISION,
|
||||||
if ($this->getArgument('diff')) {
|
);
|
||||||
$source = self::SOURCE_DIFF;
|
|
||||||
$requested++;
|
|
||||||
}
|
|
||||||
if ($this->getArgument('arcbundle')) {
|
|
||||||
$source = self::SOURCE_BUNDLE;
|
|
||||||
$requested++;
|
|
||||||
}
|
|
||||||
if ($this->getArgument('patch')) {
|
|
||||||
$source = self::SOURCE_PATCH;
|
|
||||||
$requested++;
|
|
||||||
}
|
|
||||||
|
|
||||||
$use_revision_id = null;
|
$sources = array();
|
||||||
if ($this->getArgument('name')) {
|
foreach ($arguments as $key => $source_type) {
|
||||||
$namev = $this->getArgument('name');
|
$value = $this->getArgument($key);
|
||||||
if (count($namev) > 1) {
|
if (!$value) {
|
||||||
throw new ArcanistUsageException(
|
continue;
|
||||||
pht('Specify at most one revision name.'));
|
|
||||||
}
|
}
|
||||||
$source = self::SOURCE_REVISION;
|
|
||||||
$requested++;
|
|
||||||
|
|
||||||
$use_revision_id = $this->normalizeRevisionID(head($namev));
|
switch ($key) {
|
||||||
|
case 'revision':
|
||||||
|
$value = $this->normalizeRevisionID($value);
|
||||||
|
break;
|
||||||
|
case 'name':
|
||||||
|
if (count($value) > 1) {
|
||||||
|
throw new ArcanistUsageException(
|
||||||
|
pht('Specify at most one revision name.'));
|
||||||
|
}
|
||||||
|
$value = $this->normalizeRevisionID(head($value));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sources[] = array(
|
||||||
|
$source_type,
|
||||||
|
$value,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($requested === 0) {
|
if (!$sources) {
|
||||||
throw new ArcanistUsageException(
|
throw new ArcanistUsageException(
|
||||||
pht(
|
pht(
|
||||||
"Specify one of '%s', '%s' (to select the current changes attached ".
|
'You must specify changes to apply to the working copy with '.
|
||||||
"to a Differential revision), '%s' (to select a specific, ".
|
'"D12345", "--revision", "--diff", "--arcbundle", or "--patch".'));
|
||||||
"out-of-date diff or a diff which is not attached to a revision), ".
|
|
||||||
"'%s' or '%s' to choose a patch source.",
|
|
||||||
'D12345',
|
|
||||||
'--revision <revision_id>',
|
|
||||||
'--diff <diff_id>',
|
|
||||||
'--arcbundle <file>',
|
|
||||||
'--patch <file>'));
|
|
||||||
} else if ($requested > 1) {
|
|
||||||
throw new ArcanistUsageException(
|
|
||||||
pht(
|
|
||||||
"Options '%s', '%s', '%s', '%s' and '%s' are not compatible. ".
|
|
||||||
"Choose exactly one patch source.",
|
|
||||||
'D12345',
|
|
||||||
'--revision',
|
|
||||||
'--diff',
|
|
||||||
'--arcbundle',
|
|
||||||
'--patch'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->source = $source;
|
if (count($sources) > 1) {
|
||||||
$this->sourceParam = nonempty(
|
throw new ArcanistUsageException(
|
||||||
$use_revision_id,
|
pht(
|
||||||
$this->getArgument($source));
|
'Options "D12345", "--revision", "--diff", "--arcbundle" and '.
|
||||||
|
'"--patch" are mutually exclusive. Choose exactly one patch '.
|
||||||
|
'source.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$source = head($sources);
|
||||||
|
|
||||||
|
$this->source = $source[0];
|
||||||
|
$this->sourceParam = $source[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function requiresConduit() {
|
public function requiresConduit() {
|
||||||
|
|
Loading…
Reference in a new issue