2012-05-07 15:07:23 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2012 Facebook, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write configuration settings.
|
|
|
|
*
|
|
|
|
* @group workflow
|
|
|
|
*/
|
|
|
|
final class ArcanistSetConfigWorkflow extends ArcanistBaseWorkflow {
|
|
|
|
|
|
|
|
public function getCommandSynopses() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
|
|
|
**set-config** __name__ __value__
|
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCommandHelp() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
|
|
|
Supports: cli
|
|
|
|
Sets an arc configuration option.
|
|
|
|
|
|
|
|
Values are written to '~/.arcrc' on Linux and Mac OS X, and an
|
|
|
|
undisclosed location on Windows.
|
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getArguments() {
|
|
|
|
return array(
|
|
|
|
'*' => 'argv',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function run() {
|
|
|
|
$argv = $this->getArgument('argv');
|
|
|
|
if (count($argv) != 2) {
|
|
|
|
throw new ArcanistUsageException("Specify a key and a value.");
|
|
|
|
}
|
|
|
|
|
Allow 'arc' to run without '.arcconfig'
Summary:
This is mostly an onboarding thing, but also allows "arc upload", "arc download", and "arc paste" to work anywhere on the system.
- Try to read the Phabricator install URI from arc global config if we can't find ".arcconfig".
- Build a WorkingCopy anyway if we can't find ".arcconfig", as long as we can find ".svn", ".git", or ".hg".
- Make all the workflows handle "no project ID" at least somewhat gracefully.
Test Plan:
- Ran "arc diff" in .arcconfig-less Mercurial, Git, and Subversion working copies.
- Ran "arc upload" and "arc download" from my desktop.
- Ran "arc paste" from somewhere random.
- Cleared my config and hit the error, got useful instructions.
Reviewers: btrahan, csilvers
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2424
2012-05-08 00:24:58 +02:00
|
|
|
$config = self::readGlobalArcConfig();
|
2012-05-07 15:07:23 +02:00
|
|
|
|
|
|
|
$key = $argv[0];
|
|
|
|
$val = $argv[1];
|
|
|
|
|
|
|
|
$old = null;
|
|
|
|
if (array_key_exists($key, $config)) {
|
|
|
|
$old = $config[$key];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strlen($val)) {
|
|
|
|
unset($config[$key]);
|
Allow 'arc' to run without '.arcconfig'
Summary:
This is mostly an onboarding thing, but also allows "arc upload", "arc download", and "arc paste" to work anywhere on the system.
- Try to read the Phabricator install URI from arc global config if we can't find ".arcconfig".
- Build a WorkingCopy anyway if we can't find ".arcconfig", as long as we can find ".svn", ".git", or ".hg".
- Make all the workflows handle "no project ID" at least somewhat gracefully.
Test Plan:
- Ran "arc diff" in .arcconfig-less Mercurial, Git, and Subversion working copies.
- Ran "arc upload" and "arc download" from my desktop.
- Ran "arc paste" from somewhere random.
- Cleared my config and hit the error, got useful instructions.
Reviewers: btrahan, csilvers
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2424
2012-05-08 00:24:58 +02:00
|
|
|
self::writeGlobalArcConfig($config);
|
2012-05-07 15:07:23 +02:00
|
|
|
|
|
|
|
if ($old === null) {
|
|
|
|
echo "Deleted key '{$key}'.\n";
|
|
|
|
} else {
|
|
|
|
echo "Deleted key '{$key}' (was '{$old}').\n";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$config[$key] = $val;
|
Allow 'arc' to run without '.arcconfig'
Summary:
This is mostly an onboarding thing, but also allows "arc upload", "arc download", and "arc paste" to work anywhere on the system.
- Try to read the Phabricator install URI from arc global config if we can't find ".arcconfig".
- Build a WorkingCopy anyway if we can't find ".arcconfig", as long as we can find ".svn", ".git", or ".hg".
- Make all the workflows handle "no project ID" at least somewhat gracefully.
Test Plan:
- Ran "arc diff" in .arcconfig-less Mercurial, Git, and Subversion working copies.
- Ran "arc upload" and "arc download" from my desktop.
- Ran "arc paste" from somewhere random.
- Cleared my config and hit the error, got useful instructions.
Reviewers: btrahan, csilvers
Reviewed By: csilvers
CC: aran
Differential Revision: https://secure.phabricator.com/D2424
2012-05-08 00:24:58 +02:00
|
|
|
self::writeGlobalArcConfig($config);
|
2012-05-07 15:07:23 +02:00
|
|
|
|
|
|
|
if ($old === null) {
|
|
|
|
echo "Set key '{$key}' = '{$val}'.\n";
|
|
|
|
} else {
|
|
|
|
echo "Set key '{$key}' = '{$val}' (was '{$old}').\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|