Enrich arc configuration and add stronger typing
Summary:
See <https://github.com/facebook/arcanist/issues/45>
Currently, when the user types `arc set-config x false`, we set it as the string "false", which is usually not desirable. We have some steps toward typed config already, but expand on what we have and move as much stuff as possible into it, including all the config settings that aren't currently documented (there are still some lint-specific and project-specific settings not present here, but this is most of it).
Also make the `phutil_libraries` key a legacy name for `load`, and `immutable_history` a legacy name for `history.immutable`. Generally the goal here is to make config simpler and bring it more in-line with Git/Mercurial, which use dotted hierarchies.
I'll add some documentation here but I think most of the changes should be fairly straightforward.
Test Plan:
- `arc set-config history.immutable on` (And similar -- sets to boolean true.)
- `arc set-config history.immutable off` (And similar -- sets to boolean false.)
- `arc set-config history.immutable derp` (And similar -- raises exception.)
- `arc set-config history.immutable ''` (And similar -- removes setting value.)
- `arc set-config --show`
- `arc get-config`
- `arc get-config base`
Reviewers: dschleimer, bos, btrahan, vrana
Reviewed By: dschleimer
CC: aran
Maniphest Tasks: T1546
Differential Revision: https://secure.phabricator.com/D3045
2012-07-25 18:37:09 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class ArcanistSettings {
|
|
|
|
|
|
|
|
private function getOptions() {
|
|
|
|
return array(
|
|
|
|
'default' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'help' =>
|
|
|
|
'The URI of a Phabricator install to connect to by default, if '.
|
|
|
|
'arc is run in a project without a Phabricator URI or run outside '.
|
|
|
|
'of a project.',
|
|
|
|
'example' => '"http://phabricator.example.com/"',
|
|
|
|
),
|
|
|
|
'base' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'help' =>
|
|
|
|
'Base commit ruleset to invoke when determining the start of a '.
|
|
|
|
'commit range. See "Arcanist User Guide: Commit Ranges" for '.
|
|
|
|
'details.',
|
|
|
|
'example' => '"arc:amended, arc:prompt"',
|
|
|
|
),
|
|
|
|
'load' => array(
|
|
|
|
'type' => 'list',
|
|
|
|
'legacy' => 'phutil_libraries',
|
|
|
|
'help' =>
|
|
|
|
'A list of paths to phutil libraries that should be loaded at '.
|
|
|
|
'startup. This can be used to make classes available, like lint or '.
|
|
|
|
'unit test engines.',
|
|
|
|
'example' => '["/var/arc/customlib/src"]',
|
2014-05-20 11:34:28 -07:00
|
|
|
'default' => array(),
|
Enrich arc configuration and add stronger typing
Summary:
See <https://github.com/facebook/arcanist/issues/45>
Currently, when the user types `arc set-config x false`, we set it as the string "false", which is usually not desirable. We have some steps toward typed config already, but expand on what we have and move as much stuff as possible into it, including all the config settings that aren't currently documented (there are still some lint-specific and project-specific settings not present here, but this is most of it).
Also make the `phutil_libraries` key a legacy name for `load`, and `immutable_history` a legacy name for `history.immutable`. Generally the goal here is to make config simpler and bring it more in-line with Git/Mercurial, which use dotted hierarchies.
I'll add some documentation here but I think most of the changes should be fairly straightforward.
Test Plan:
- `arc set-config history.immutable on` (And similar -- sets to boolean true.)
- `arc set-config history.immutable off` (And similar -- sets to boolean false.)
- `arc set-config history.immutable derp` (And similar -- raises exception.)
- `arc set-config history.immutable ''` (And similar -- removes setting value.)
- `arc set-config --show`
- `arc get-config`
- `arc get-config base`
Reviewers: dschleimer, bos, btrahan, vrana
Reviewed By: dschleimer
CC: aran
Maniphest Tasks: T1546
Differential Revision: https://secure.phabricator.com/D3045
2012-07-25 18:37:09 -07:00
|
|
|
),
|
Allow `arc` to identify repositories without "project_id"
Summary:
Ref T4343. Continues the process of reducing the prominence of Arcanist Projects. Primarily:
- Query Phabricator to identify the working copy based on explicit configuration, or guess based on heuristics.
- Enhance `arc which` to explain the process to the user.
- The `project_id` key is no longer required in `.arcconfig`.
Minor/cleanup changes:
- Rename `project_id` to `project.name` (consistency, clarity).
- Rename `conduit_uri` to `phabricator.uri` (consistency, clairty).
- These both need documentation updates.
- Add `repository.callsign` to explicitly bind to a repository.
- Updated `.arcconfig` for the new values.
- Fix a unit test which broke a while ago when we fixed a rare definition of "unstaged".
- Make `getRepositoryUUID()` generic so we can get rid of one `instanceof`.
Test Plan:
- Ran `arc which`.
- Ran `arc diff`.
- This doesn't really change anything, so the only real risk is version compatibility breaks. This //does// introduce such a break, but the window is very narrow: if you upgrade `arc` after this commit, and try to diff against a Phabricator which was updated after yesterday (D8068) but before D8072 lands, the lookup will work so we'll add `repositoryPHID` to the `differential.creatediff` call, but it won't exist in Phabricator yet. This window is so narrow that I'm not going to try to fix it, as I'd guess there is a significant chance that no users will be affected. I don't see a clever way to fix it that doesn't involve a lot of work, either.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T4343
Differential Revision: https://secure.phabricator.com/D8073
2014-01-26 15:31:30 -08:00
|
|
|
'repository.callsign' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'example' => '"X"',
|
|
|
|
'help' => pht(
|
|
|
|
'Associate the working copy with a specific Phabricator repository. '.
|
|
|
|
'Normally, arc can figure this association out on its own, but if '.
|
|
|
|
'your setup is unusual you can use this option to tell it what the '.
|
|
|
|
'desired value is.'),
|
|
|
|
),
|
|
|
|
'phabricator.uri' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'legacy' => 'conduit_uri',
|
|
|
|
'example' => '"https://phabricator.mycompany.com/"',
|
|
|
|
'help' => pht(
|
|
|
|
'Associates this working copy with a specific installation of '.
|
|
|
|
'Phabricator.'),
|
|
|
|
),
|
|
|
|
'project.name' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'legacy' => 'project_id',
|
|
|
|
'example' => '"arcanist"',
|
|
|
|
'help' => pht(
|
|
|
|
'Associates this working copy with a named Arcanist Project. '.
|
|
|
|
'This is primarily useful if you use SVN and have several different '.
|
|
|
|
'projects in the same repository.'),
|
|
|
|
),
|
Enrich arc configuration and add stronger typing
Summary:
See <https://github.com/facebook/arcanist/issues/45>
Currently, when the user types `arc set-config x false`, we set it as the string "false", which is usually not desirable. We have some steps toward typed config already, but expand on what we have and move as much stuff as possible into it, including all the config settings that aren't currently documented (there are still some lint-specific and project-specific settings not present here, but this is most of it).
Also make the `phutil_libraries` key a legacy name for `load`, and `immutable_history` a legacy name for `history.immutable`. Generally the goal here is to make config simpler and bring it more in-line with Git/Mercurial, which use dotted hierarchies.
I'll add some documentation here but I think most of the changes should be fairly straightforward.
Test Plan:
- `arc set-config history.immutable on` (And similar -- sets to boolean true.)
- `arc set-config history.immutable off` (And similar -- sets to boolean false.)
- `arc set-config history.immutable derp` (And similar -- raises exception.)
- `arc set-config history.immutable ''` (And similar -- removes setting value.)
- `arc set-config --show`
- `arc get-config`
- `arc get-config base`
Reviewers: dschleimer, bos, btrahan, vrana
Reviewed By: dschleimer
CC: aran
Maniphest Tasks: T1546
Differential Revision: https://secure.phabricator.com/D3045
2012-07-25 18:37:09 -07:00
|
|
|
'lint.engine' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'legacy' => 'lint_engine',
|
|
|
|
'help' =>
|
|
|
|
'The name of a default lint engine to use, if no lint engine is '.
|
|
|
|
'specified by the current project.',
|
|
|
|
'example' => '"ExampleLintEngine"',
|
|
|
|
),
|
|
|
|
'unit.engine' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'legacy' => 'unit_engine',
|
|
|
|
'help' =>
|
|
|
|
'The name of a default unit test engine to use, if no unit test '.
|
|
|
|
'engine is specified by the current project.',
|
|
|
|
'example' => '"ExampleUnitTestEngine"',
|
|
|
|
),
|
2013-04-14 11:48:22 -07:00
|
|
|
'arc.feature.start.default' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'help' =>
|
|
|
|
'The name of the default branch to create the new feature branch '.
|
|
|
|
'off of.',
|
|
|
|
'example' => '"develop"',
|
|
|
|
),
|
Enrich arc configuration and add stronger typing
Summary:
See <https://github.com/facebook/arcanist/issues/45>
Currently, when the user types `arc set-config x false`, we set it as the string "false", which is usually not desirable. We have some steps toward typed config already, but expand on what we have and move as much stuff as possible into it, including all the config settings that aren't currently documented (there are still some lint-specific and project-specific settings not present here, but this is most of it).
Also make the `phutil_libraries` key a legacy name for `load`, and `immutable_history` a legacy name for `history.immutable`. Generally the goal here is to make config simpler and bring it more in-line with Git/Mercurial, which use dotted hierarchies.
I'll add some documentation here but I think most of the changes should be fairly straightforward.
Test Plan:
- `arc set-config history.immutable on` (And similar -- sets to boolean true.)
- `arc set-config history.immutable off` (And similar -- sets to boolean false.)
- `arc set-config history.immutable derp` (And similar -- raises exception.)
- `arc set-config history.immutable ''` (And similar -- removes setting value.)
- `arc set-config --show`
- `arc get-config`
- `arc get-config base`
Reviewers: dschleimer, bos, btrahan, vrana
Reviewed By: dschleimer
CC: aran
Maniphest Tasks: T1546
Differential Revision: https://secure.phabricator.com/D3045
2012-07-25 18:37:09 -07:00
|
|
|
'arc.land.onto.default' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'help' =>
|
|
|
|
'The name of the default branch to land changes onto when '.
|
|
|
|
'`arc land` is run.',
|
|
|
|
'example' => '"develop"',
|
|
|
|
),
|
2013-04-14 11:48:22 -07:00
|
|
|
'arc.land.update.default' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'help' =>
|
|
|
|
'The default strategy to use when arc land updates the feature '.
|
|
|
|
'branch. Supports \'rebase\' and \'merge\' strategies.',
|
|
|
|
'example' => '"rebase"',
|
|
|
|
),
|
Disable lint cache by default
Summary:
Fixes T2266. Motivation:
- The lint cache does not always invalidate correctly. Because of the nature of the cache, this is a hard problem (right after "naming things").
- We already have a fair amount of complexity in trying to invalidate it, and are still discovering new places where it doesn't work (e.g., Windows with "/" vs "\" paths).
- One invalidation failure is when linter code changes, which seems unresolvable in the general case (e.g., changes to external linters).
- It's not obvious what's happening when the lint cache causes some kind of issue.
- Particularly while developing or debugging linters, your changes often won't be reflected in the lint output. Some of this is theoretically tractable but the external linter case probably isn't.
- When someone reports a problem with the lint cache in IRC or elsewhere, there is essentially never a way for me to fix it. The lint cache can't be debugged effectively without access to a working copy where the problem reproduces.
- The cache provides limited benefit outside of Facebook's install.
To remedy these issues:
- Introduce configuration which controls cache usage.
- Default it off.
- Print a message when the cache is in use.
(I'd tentatively support removing the cache entirely, but I don't know how @vrana and Facebook feel about that.)
Test Plan: Ran `arc set-config --show`, `arc lint --cache 0`, `arc lint --cache 1`.
Reviewers: vrana, btrahan
Reviewed By: vrana
CC: aran, mbishopim3, nh, edward, wez
Maniphest Tasks: T2266
Differential Revision: https://secure.phabricator.com/D5766
2013-04-23 11:26:28 -07:00
|
|
|
'arc.lint.cache' => array(
|
|
|
|
'type' => 'bool',
|
|
|
|
'help' =>
|
|
|
|
"Enable the lint cache by default. When enabled, 'arc lint' ".
|
|
|
|
"attempts to use cached results if possible. Currently, the cache ".
|
|
|
|
"is not always invalidated correctly and may cause 'arc lint' to ".
|
|
|
|
"report incorrect results, particularly while developing linters. ".
|
|
|
|
"This is probably worth enabling only if your linters are very slow.",
|
|
|
|
'example' => 'false',
|
2014-05-20 11:34:28 -07:00
|
|
|
'default' => false,
|
Disable lint cache by default
Summary:
Fixes T2266. Motivation:
- The lint cache does not always invalidate correctly. Because of the nature of the cache, this is a hard problem (right after "naming things").
- We already have a fair amount of complexity in trying to invalidate it, and are still discovering new places where it doesn't work (e.g., Windows with "/" vs "\" paths).
- One invalidation failure is when linter code changes, which seems unresolvable in the general case (e.g., changes to external linters).
- It's not obvious what's happening when the lint cache causes some kind of issue.
- Particularly while developing or debugging linters, your changes often won't be reflected in the lint output. Some of this is theoretically tractable but the external linter case probably isn't.
- When someone reports a problem with the lint cache in IRC or elsewhere, there is essentially never a way for me to fix it. The lint cache can't be debugged effectively without access to a working copy where the problem reproduces.
- The cache provides limited benefit outside of Facebook's install.
To remedy these issues:
- Introduce configuration which controls cache usage.
- Default it off.
- Print a message when the cache is in use.
(I'd tentatively support removing the cache entirely, but I don't know how @vrana and Facebook feel about that.)
Test Plan: Ran `arc set-config --show`, `arc lint --cache 0`, `arc lint --cache 1`.
Reviewers: vrana, btrahan
Reviewed By: vrana
CC: aran, mbishopim3, nh, edward, wez
Maniphest Tasks: T2266
Differential Revision: https://secure.phabricator.com/D5766
2013-04-23 11:26:28 -07:00
|
|
|
),
|
Enrich arc configuration and add stronger typing
Summary:
See <https://github.com/facebook/arcanist/issues/45>
Currently, when the user types `arc set-config x false`, we set it as the string "false", which is usually not desirable. We have some steps toward typed config already, but expand on what we have and move as much stuff as possible into it, including all the config settings that aren't currently documented (there are still some lint-specific and project-specific settings not present here, but this is most of it).
Also make the `phutil_libraries` key a legacy name for `load`, and `immutable_history` a legacy name for `history.immutable`. Generally the goal here is to make config simpler and bring it more in-line with Git/Mercurial, which use dotted hierarchies.
I'll add some documentation here but I think most of the changes should be fairly straightforward.
Test Plan:
- `arc set-config history.immutable on` (And similar -- sets to boolean true.)
- `arc set-config history.immutable off` (And similar -- sets to boolean false.)
- `arc set-config history.immutable derp` (And similar -- raises exception.)
- `arc set-config history.immutable ''` (And similar -- removes setting value.)
- `arc set-config --show`
- `arc get-config`
- `arc get-config base`
Reviewers: dschleimer, bos, btrahan, vrana
Reviewed By: dschleimer
CC: aran
Maniphest Tasks: T1546
Differential Revision: https://secure.phabricator.com/D3045
2012-07-25 18:37:09 -07:00
|
|
|
'history.immutable' => array(
|
|
|
|
'type' => 'bool',
|
|
|
|
'legacy' => 'immutable_history',
|
|
|
|
'help' =>
|
|
|
|
'If true, arc will never change repository history (e.g., through '.
|
|
|
|
'amending or rebasing). Defaults to true in Mercurial and false in '.
|
|
|
|
'Git. This setting has no effect in Subversion.',
|
|
|
|
'example' => 'false',
|
|
|
|
),
|
|
|
|
'editor' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'help' =>
|
|
|
|
"Command to use to invoke an interactive editor, like 'nano' or ".
|
|
|
|
"'vim'. This setting overrides the EDITOR environmental variable.",
|
|
|
|
'example' => '"nano"',
|
|
|
|
),
|
2013-08-04 08:21:35 -07:00
|
|
|
'https.cabundle' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'help' =>
|
|
|
|
"Path to a custom CA bundle file to be used for arcanist's cURL ".
|
|
|
|
"calls. This is used primarily when your conduit endpoint is ".
|
|
|
|
"behind https signed by your organization's internal CA.",
|
2014-09-27 10:21:23 +10:00
|
|
|
'example' => 'support/yourca.pem',
|
2013-08-04 08:21:35 -07:00
|
|
|
),
|
2013-09-25 15:26:38 -07:00
|
|
|
'https.blindly-trust-domains' => array(
|
|
|
|
'type' => 'list',
|
|
|
|
'help' => 'List of domains to blindly trust SSL certificates for. '.
|
|
|
|
'Disables peer verification.',
|
|
|
|
'example' => '["secure.mycompany.com"]',
|
2014-05-20 11:34:28 -07:00
|
|
|
'default' => array(),
|
2013-09-25 15:26:38 -07:00
|
|
|
),
|
2012-12-09 14:09:35 -08:00
|
|
|
'browser' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'help' =>
|
2014-05-23 13:53:05 -07:00
|
|
|
'Command to use to invoke a web browser.',
|
2012-12-09 14:09:35 -08:00
|
|
|
'example' => '"gnome-www-browser"',
|
|
|
|
),
|
2012-09-05 11:45:54 -07:00
|
|
|
'events.listeners' => array(
|
|
|
|
'type' => 'list',
|
|
|
|
'help' => 'List of event listener classes to install at startup.',
|
|
|
|
'example' => '["ExampleEventListener"]',
|
2014-05-20 11:34:28 -07:00
|
|
|
'default' => array(),
|
2012-09-05 11:45:54 -07:00
|
|
|
),
|
2012-12-17 17:58:53 -08:00
|
|
|
'http.basicauth.user' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'help' =>
|
2014-05-23 13:53:05 -07:00
|
|
|
'Username to use for basic auth over http transports',
|
2012-12-17 17:58:53 -08:00
|
|
|
'example' => '"bob"',
|
|
|
|
),
|
|
|
|
'http.basicauth.pass' => array(
|
|
|
|
'type' => 'string',
|
|
|
|
'help' =>
|
2014-05-23 13:53:05 -07:00
|
|
|
'Password to use for basic auth over http transports',
|
2012-12-17 17:58:53 -08:00
|
|
|
'example' => '"bobhasasecret"',
|
|
|
|
),
|
2013-03-21 15:51:39 -07:00
|
|
|
'arc.autostash' => array(
|
|
|
|
'type' => 'bool',
|
|
|
|
'help' =>
|
|
|
|
'Whether arc should permit the automatic stashing of changes in '.
|
2014-07-09 09:12:13 +10:00
|
|
|
'the working directory when requiring a clean working copy. '.
|
2013-03-21 15:51:39 -07:00
|
|
|
'This option should only be used when users understand how '.
|
|
|
|
'to restore their working directory from the local stash if '.
|
|
|
|
'an Arcanist operation causes an unrecoverable error.',
|
|
|
|
'example' => 'false',
|
2014-05-20 11:34:28 -07:00
|
|
|
'default' => false,
|
2013-03-21 15:51:39 -07:00
|
|
|
),
|
Enrich arc configuration and add stronger typing
Summary:
See <https://github.com/facebook/arcanist/issues/45>
Currently, when the user types `arc set-config x false`, we set it as the string "false", which is usually not desirable. We have some steps toward typed config already, but expand on what we have and move as much stuff as possible into it, including all the config settings that aren't currently documented (there are still some lint-specific and project-specific settings not present here, but this is most of it).
Also make the `phutil_libraries` key a legacy name for `load`, and `immutable_history` a legacy name for `history.immutable`. Generally the goal here is to make config simpler and bring it more in-line with Git/Mercurial, which use dotted hierarchies.
I'll add some documentation here but I think most of the changes should be fairly straightforward.
Test Plan:
- `arc set-config history.immutable on` (And similar -- sets to boolean true.)
- `arc set-config history.immutable off` (And similar -- sets to boolean false.)
- `arc set-config history.immutable derp` (And similar -- raises exception.)
- `arc set-config history.immutable ''` (And similar -- removes setting value.)
- `arc set-config --show`
- `arc get-config`
- `arc get-config base`
Reviewers: dschleimer, bos, btrahan, vrana
Reviewed By: dschleimer
CC: aran
Maniphest Tasks: T1546
Differential Revision: https://secure.phabricator.com/D3045
2012-07-25 18:37:09 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getOption($key) {
|
|
|
|
return idx($this->getOptions(), $key, array());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAllKeys() {
|
|
|
|
return array_keys($this->getOptions());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getHelp($key) {
|
|
|
|
return idx($this->getOption($key), 'help');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getExample($key) {
|
|
|
|
return idx($this->getOption($key), 'example');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getType($key) {
|
|
|
|
return idx($this->getOption($key), 'type', 'wild');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getLegacyName($key) {
|
|
|
|
return idx($this->getOption($key), 'legacy');
|
|
|
|
}
|
|
|
|
|
2014-05-20 11:34:28 -07:00
|
|
|
public function getDefaultSettings() {
|
|
|
|
$defaults = array();
|
|
|
|
foreach ($this->getOptions() as $key => $option) {
|
|
|
|
if (array_key_exists('default', $option)) {
|
|
|
|
$defaults[$key] = $option['default'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $defaults;
|
|
|
|
}
|
|
|
|
|
Enrich arc configuration and add stronger typing
Summary:
See <https://github.com/facebook/arcanist/issues/45>
Currently, when the user types `arc set-config x false`, we set it as the string "false", which is usually not desirable. We have some steps toward typed config already, but expand on what we have and move as much stuff as possible into it, including all the config settings that aren't currently documented (there are still some lint-specific and project-specific settings not present here, but this is most of it).
Also make the `phutil_libraries` key a legacy name for `load`, and `immutable_history` a legacy name for `history.immutable`. Generally the goal here is to make config simpler and bring it more in-line with Git/Mercurial, which use dotted hierarchies.
I'll add some documentation here but I think most of the changes should be fairly straightforward.
Test Plan:
- `arc set-config history.immutable on` (And similar -- sets to boolean true.)
- `arc set-config history.immutable off` (And similar -- sets to boolean false.)
- `arc set-config history.immutable derp` (And similar -- raises exception.)
- `arc set-config history.immutable ''` (And similar -- removes setting value.)
- `arc set-config --show`
- `arc get-config`
- `arc get-config base`
Reviewers: dschleimer, bos, btrahan, vrana
Reviewed By: dschleimer
CC: aran
Maniphest Tasks: T1546
Differential Revision: https://secure.phabricator.com/D3045
2012-07-25 18:37:09 -07:00
|
|
|
public function willWriteValue($key, $value) {
|
|
|
|
$type = $this->getType($key);
|
|
|
|
switch ($type) {
|
|
|
|
case 'bool':
|
|
|
|
if (strtolower($value) === 'false' ||
|
|
|
|
strtolower($value) === 'no' ||
|
|
|
|
strtolower($value) === 'off' ||
|
|
|
|
$value === '' ||
|
|
|
|
$value === '0' ||
|
|
|
|
$value === 0 ||
|
|
|
|
$value === false) {
|
|
|
|
$value = false;
|
|
|
|
} else if (strtolower($value) === 'true' ||
|
|
|
|
strtolower($value) === 'yes' ||
|
|
|
|
strtolower($value) === 'on' ||
|
|
|
|
$value === '1' ||
|
|
|
|
$value === 1 ||
|
|
|
|
$value === true) {
|
|
|
|
$value = true;
|
|
|
|
} else {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"Type of setting '{$key}' must be boolean, like 'true' or ".
|
|
|
|
"'false'.");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'list':
|
|
|
|
if (is_array($value)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_string($value)) {
|
|
|
|
$list = json_decode($value, true);
|
|
|
|
if (is_array($list)) {
|
|
|
|
$value = $list;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$list_example = '["apple", "banana", "cherry"]';
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"Type of setting '{$key}' must be list. You can specify a list ".
|
|
|
|
"in JSON, like: {$list_example}");
|
|
|
|
|
|
|
|
case 'string':
|
|
|
|
if (!is_scalar($value)) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"Type of setting '{$key}' must be string.");
|
|
|
|
}
|
|
|
|
$value = (string)$value;
|
|
|
|
break;
|
|
|
|
case 'wild':
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function willReadValue($key, $value) {
|
|
|
|
$type = $this->getType($key);
|
|
|
|
switch ($type) {
|
|
|
|
case 'string':
|
|
|
|
if (!is_string($value)) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"Type of setting '{$key}' must be string.");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'bool':
|
|
|
|
if ($value !== true && $value !== false) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"Type of setting '{$key}' must be boolean.");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'list':
|
|
|
|
if (!is_array($value)) {
|
|
|
|
throw new ArcanistUsageException(
|
|
|
|
"Type of setting '{$key}' must be list.");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'wild':
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function formatConfigValueForDisplay($key, $value) {
|
|
|
|
if ($value === false) {
|
|
|
|
return 'false';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($value === true) {
|
|
|
|
return 'true';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($value === null) {
|
|
|
|
return 'null';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_string($value)) {
|
|
|
|
return '"'.$value.'"';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_array($value)) {
|
|
|
|
// TODO: Both json_encode() and PhutilJSON do a bad job with one-liners.
|
|
|
|
// PhutilJSON splits them across a bunch of lines, while json_encode()
|
|
|
|
// escapes all kinds of stuff like "/". It would be nice if PhutilJSON
|
|
|
|
// had a mode for pretty one-liners.
|
|
|
|
$value = json_encode($value);
|
|
|
|
|
|
|
|
// json_encode() unnecessarily escapes "/" to prevent "</script>" stuff,
|
|
|
|
// optimistically unescape it for display to improve readability.
|
|
|
|
$value = preg_replace('@(?<!\\\\)\\\\/@', '/', $value);
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|