1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-08 16:02:39 +01:00

[Wilds] When reading ".arcrc" files, modernize the data we read in-process if they're in an older format on disk

Summary:
See T13098. All ".arcconfig" files except "~/.arcrc" have config keys at top level.

"~/.arcrc" previously had "aliases" at top level, and currently has "hosts" at top level. "aliases" became standard configuration. I'd like to make "hosts" standard configuration too -- one reason to do this is to make automation with `--config-file` easier, so you can shove API tokens in a file somewhere (and not need a home directory). Another reason is just to standardize things.

If we read "~/.arcrc" and see a "config" key, put all those keys at top level and then fill in anything else left over so we end up with `~/.arcrc` that effectively looks like other "arcconfig" files. I'd possibly like to rename this file to "arcconfig" at some point, too, but that can happen later.

Test Plan: Ran `arc get-config`, which barely works, but now read my `~/.arcrc` somewhat more successfully.

Reviewers: amckinley

Reviewed By: amckinley

Differential Revision: https://secure.phabricator.com/D19696
This commit is contained in:
epriestley 2018-09-19 11:02:31 -07:00
parent c64f86c2f6
commit 5ef6599239
3 changed files with 60 additions and 0 deletions

View file

@ -178,6 +178,22 @@ final class ArcanistConfigurationEngine
ArcanistConfigurationEngineExtension $extension,
$is_alias_of = null) {
$reserved = array(
// The presence of this key is used to detect old "~/.arcrc" files, so
// configuration options may not use it.
'config',
);
$reserved = array_fuse($reserved);
if (isset($reserved[$key])) {
throw new Exception(
pht(
'Extension ("%s") defines invalid configuration with key "%s". '.
'This key is reserved.',
get_class($extension),
$key));
}
$is_ok = preg_match('(^[a-z][a-z0-9._-]{2,}\z)', $key);
if (!$is_ok) {
if ($is_alias_of === null) {

View file

@ -16,6 +16,8 @@ abstract class ArcanistFilesystemConfigurationSource
}
}
$values = $this->didReadFilesystemValues($values);
parent::__construct($values);
}
@ -29,4 +31,8 @@ abstract class ArcanistFilesystemConfigurationSource
abstract public function getFileKindDisplayName();
protected function didReadFilesystemValues(array $values) {
return $values;
}
}

View file

@ -7,4 +7,42 @@ final class ArcanistUserConfigurationSource
return pht('User Config File');
}
public function didReadFilesystemValues(array $values) {
// Before toolsets, the "~/.arcrc" file had separate top-level keys for
// "config", "hosts", and "aliases". Transform this older file format into
// a more modern format.
if (!isset($values['config'])) {
// This isn't an older file, so just return the values unmodified.
return $values;
}
// Make the keys in "config" top-level keys. Then add in whatever other
// top level keys exist, other than "config", preferring keys that already
// exist in the "config" dictionary.
// For example, this older configuration file:
//
// {
// "hosts": ...,
// "config": {x: ..., y: ...},
// "aliases": ...
// }
//
// ...becomes this modern file:
//
// {
// "x": ...,
// "y": ...,
// "hosts": ...,
// "aliases": ...
// }
$result = $values['config'];
unset($values['config']);
$result += $values;
return $result;
}
}