2012-05-07 15:07:23 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write configuration settings.
|
|
|
|
*/
|
2014-07-21 23:49:15 +02:00
|
|
|
final class ArcanistSetConfigWorkflow extends ArcanistWorkflow {
|
2012-05-07 15:07:23 +02:00
|
|
|
|
Make Arcanist workflow names explicit
Summary:
Currently, adding a new workflow requires you to override ArcanistConfiguration, which is messy. Instead, just load everything that extends ArcanistBaseWorkflow.
Remove all the rules tying workflow names to class names through arcane incantations.
This has a very small performance cost in that we need to load every Workflow class every time now, but we don't hit __init__ and such anymore and it was pretty negligible on my machine (98ms vs 104ms or something).
Test Plan: Ran "arc help", "arc which", "arc diff", etc.
Reviewers: edward, vrana, btrahan
Reviewed By: edward
CC: aran, zeeg
Differential Revision: https://secure.phabricator.com/D3691
2012-10-17 17:35:03 +02:00
|
|
|
public function getWorkflowName() {
|
|
|
|
return 'set-config';
|
|
|
|
}
|
|
|
|
|
2012-05-07 15:07:23 +02:00
|
|
|
public function getCommandSynopses() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
2012-06-14 01:02:29 +02:00
|
|
|
**set-config** [__options__] -- __name__ __value__
|
2012-05-07 15:07:23 +02:00
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCommandHelp() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
|
|
|
Supports: cli
|
|
|
|
Sets an arc configuration option.
|
|
|
|
|
2013-10-19 01:10:06 +02:00
|
|
|
Options are either user (apply to all arc commands you invoke
|
2012-06-14 01:02:29 +02:00
|
|
|
from the current user) or local (apply only to the current working
|
2014-07-09 01:12:13 +02:00
|
|
|
copy). By default, user configuration is written. Use __--local__
|
2012-06-14 01:02:29 +02:00
|
|
|
to write local configuration.
|
|
|
|
|
2013-10-19 01:10:06 +02:00
|
|
|
User values are written to '~/.arcrc' on Linux and Mac OS X, and an
|
2014-07-09 01:12:13 +02:00
|
|
|
undisclosed location on Windows. Local values are written to an arc
|
2012-06-14 01:02:29 +02:00
|
|
|
directory under either .git, .hg, or .svn as appropriate.
|
2012-05-07 15:07:23 +02:00
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getArguments() {
|
|
|
|
return array(
|
2012-06-14 01:02:29 +02:00
|
|
|
'local' => array(
|
2013-10-19 01:10:06 +02:00
|
|
|
'help' => 'Set a local config value instead of a user one',
|
2012-06-14 01:02:29 +02:00
|
|
|
),
|
2012-05-07 15:07:23 +02:00
|
|
|
'*' => 'argv',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-06-14 01:02:29 +02:00
|
|
|
public function requiresRepositoryAPI() {
|
|
|
|
return $this->getArgument('local');
|
|
|
|
}
|
|
|
|
|
2012-05-07 15:07:23 +02:00
|
|
|
public function run() {
|
|
|
|
$argv = $this->getArgument('argv');
|
|
|
|
if (count($argv) != 2) {
|
Allow global config to load libraries and set test engines
Summary:
Khan Academy is looking into lint configuration, but doesn't use ".arcconfig" because they have a large number of repositories. Making configuration more flexible generally gives us more options for onboarding installs.
- Currently, only project config (".arcconfig") can load libraries. Allow user config ("~/.arcrc") to load libraries as well.
- Currently, only project config can set lint/unit engines. Allow user config to set default lint/unit engines.
- Add some type checking to "arc set-config".
- Add "arc set-config --show".
Test Plan:
- **load**
- Ran `arc set-config load xxx`, got error about format.
- Ran `arc set-config load ["apple"]`, got warning on running 'arc' commands (no such library) but was able to run 'arc set-config' again to clear it.
- Ran `arc set-config load ["/path/to/a/lib/src/"]`, worked.
- Ran `arc list --trace`, verified my library loaded in addition to `.arcconfig` libraries.
- Ran `arc list --load-phutil-library=xxx --trace`, verified only that library loaded.
- Ran `arc list --trace --load-phutil-library=apple --trace`, got hard error about bad library.
- Set `.arcconfig` to point at a bad library, verified hard error.
- **lint.engine** / **unit.engine**
- Removed lint engine from `.arcconfig`, ran "arc lint", got a run with specified engine.
- Removed unit engine from `.arcconfig`, ran "arc unit", got a run with specified engine.
- **--show**
- Ran `arc set-config --show`.
- **misc**
- Ran `arc get-config`.
Reviewers: csilvers, btrahan, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2618
2012-05-31 20:41:39 +02:00
|
|
|
throw new ArcanistUsageException(
|
2014-05-20 20:34:28 +02:00
|
|
|
pht('Specify a key and a value.'));
|
2012-05-07 15:07:23 +02:00
|
|
|
}
|
2013-10-19 01:10:06 +02:00
|
|
|
$configuration_manager = $this->getConfigurationManager();
|
2012-05-07 15:07:23 +02:00
|
|
|
|
2012-06-14 01:02:29 +02:00
|
|
|
$is_local = $this->getArgument('local');
|
|
|
|
|
|
|
|
if ($is_local) {
|
2013-10-19 01:10:06 +02:00
|
|
|
$config = $configuration_manager->readLocalArcConfig();
|
2012-06-14 01:02:29 +02:00
|
|
|
$which = 'local';
|
|
|
|
} else {
|
2013-10-19 01:10:06 +02:00
|
|
|
$config = $configuration_manager->readUserArcConfig();
|
|
|
|
$which = 'user';
|
2012-06-14 01:02:29 +02:00
|
|
|
}
|
2012-05-07 15:07:23 +02:00
|
|
|
|
|
|
|
$key = $argv[0];
|
|
|
|
$val = $argv[1];
|
|
|
|
|
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-26 03:37:09 +02:00
|
|
|
$settings = new ArcanistSettings();
|
|
|
|
|
2012-05-07 15:07:23 +02:00
|
|
|
$old = null;
|
|
|
|
if (array_key_exists($key, $config)) {
|
|
|
|
$old = $config[$key];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strlen($val)) {
|
|
|
|
unset($config[$key]);
|
2012-06-14 01:02:29 +02:00
|
|
|
if ($is_local) {
|
2013-10-19 01:10:06 +02:00
|
|
|
$configuration_manager->writeLocalArcConfig($config);
|
2012-06-14 01:02:29 +02:00
|
|
|
} else {
|
2013-10-19 01:10:06 +02:00
|
|
|
$configuration_manager->writeUserArcConfig($config);
|
2012-06-14 01:02:29 +02:00
|
|
|
}
|
2012-05-07 15:07:23 +02: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-26 03:37:09 +02:00
|
|
|
$old = $settings->formatConfigValueForDisplay($key, $old);
|
|
|
|
|
2012-05-07 15:07:23 +02:00
|
|
|
if ($old === null) {
|
2012-06-14 01:02:29 +02:00
|
|
|
echo "Deleted key '{$key}' from {$which} config.\n";
|
2012-05-07 15:07:23 +02:00
|
|
|
} else {
|
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-26 03:37:09 +02:00
|
|
|
echo "Deleted key '{$key}' from {$which} config (was {$old}).\n";
|
2012-05-07 15:07:23 +02:00
|
|
|
}
|
|
|
|
} else {
|
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-26 03:37:09 +02:00
|
|
|
$val = $settings->willWriteValue($key, $val);
|
Allow global config to load libraries and set test engines
Summary:
Khan Academy is looking into lint configuration, but doesn't use ".arcconfig" because they have a large number of repositories. Making configuration more flexible generally gives us more options for onboarding installs.
- Currently, only project config (".arcconfig") can load libraries. Allow user config ("~/.arcrc") to load libraries as well.
- Currently, only project config can set lint/unit engines. Allow user config to set default lint/unit engines.
- Add some type checking to "arc set-config".
- Add "arc set-config --show".
Test Plan:
- **load**
- Ran `arc set-config load xxx`, got error about format.
- Ran `arc set-config load ["apple"]`, got warning on running 'arc' commands (no such library) but was able to run 'arc set-config' again to clear it.
- Ran `arc set-config load ["/path/to/a/lib/src/"]`, worked.
- Ran `arc list --trace`, verified my library loaded in addition to `.arcconfig` libraries.
- Ran `arc list --load-phutil-library=xxx --trace`, verified only that library loaded.
- Ran `arc list --trace --load-phutil-library=apple --trace`, got hard error about bad library.
- Set `.arcconfig` to point at a bad library, verified hard error.
- **lint.engine** / **unit.engine**
- Removed lint engine from `.arcconfig`, ran "arc lint", got a run with specified engine.
- Removed unit engine from `.arcconfig`, ran "arc unit", got a run with specified engine.
- **--show**
- Ran `arc set-config --show`.
- **misc**
- Ran `arc get-config`.
Reviewers: csilvers, btrahan, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2618
2012-05-31 20:41:39 +02:00
|
|
|
|
2012-05-07 15:07:23 +02:00
|
|
|
$config[$key] = $val;
|
2012-06-14 01:02:29 +02:00
|
|
|
if ($is_local) {
|
2013-10-19 01:10:06 +02:00
|
|
|
$configuration_manager->writeLocalArcConfig($config);
|
2012-06-14 01:02:29 +02:00
|
|
|
} else {
|
2013-10-19 01:10:06 +02:00
|
|
|
$configuration_manager->writeUserArcConfig($config);
|
2012-06-14 01:02:29 +02:00
|
|
|
}
|
2012-05-07 15:07:23 +02: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-26 03:37:09 +02:00
|
|
|
$val = $settings->formatConfigValueForDisplay($key, $val);
|
|
|
|
$old = $settings->formatConfigValueForDisplay($key, $old);
|
Allow global config to load libraries and set test engines
Summary:
Khan Academy is looking into lint configuration, but doesn't use ".arcconfig" because they have a large number of repositories. Making configuration more flexible generally gives us more options for onboarding installs.
- Currently, only project config (".arcconfig") can load libraries. Allow user config ("~/.arcrc") to load libraries as well.
- Currently, only project config can set lint/unit engines. Allow user config to set default lint/unit engines.
- Add some type checking to "arc set-config".
- Add "arc set-config --show".
Test Plan:
- **load**
- Ran `arc set-config load xxx`, got error about format.
- Ran `arc set-config load ["apple"]`, got warning on running 'arc' commands (no such library) but was able to run 'arc set-config' again to clear it.
- Ran `arc set-config load ["/path/to/a/lib/src/"]`, worked.
- Ran `arc list --trace`, verified my library loaded in addition to `.arcconfig` libraries.
- Ran `arc list --load-phutil-library=xxx --trace`, verified only that library loaded.
- Ran `arc list --trace --load-phutil-library=apple --trace`, got hard error about bad library.
- Set `.arcconfig` to point at a bad library, verified hard error.
- **lint.engine** / **unit.engine**
- Removed lint engine from `.arcconfig`, ran "arc lint", got a run with specified engine.
- Removed unit engine from `.arcconfig`, ran "arc unit", got a run with specified engine.
- **--show**
- Ran `arc set-config --show`.
- **misc**
- Ran `arc get-config`.
Reviewers: csilvers, btrahan, vrana
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2618
2012-05-31 20:41:39 +02:00
|
|
|
|
2012-05-07 15:07:23 +02:00
|
|
|
if ($old === null) {
|
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-26 03:37:09 +02:00
|
|
|
echo "Set key '{$key}' = {$val} in {$which} config.\n";
|
2012-05-07 15:07:23 +02:00
|
|
|
} else {
|
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-26 03:37:09 +02:00
|
|
|
echo "Set key '{$key}' = {$val} in {$which} config (was {$old}).\n";
|
2012-05-07 15:07:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|