Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F969829
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
10 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/workflow/ArcanistSetConfigWorkflow.php b/src/workflow/ArcanistSetConfigWorkflow.php
index ffd16f50..3781cffa 100644
--- a/src/workflow/ArcanistSetConfigWorkflow.php
+++ b/src/workflow/ArcanistSetConfigWorkflow.php
@@ -1,157 +1,157 @@
<?php
/**
* Write configuration settings.
*
* @group workflow
*/
final class ArcanistSetConfigWorkflow extends ArcanistBaseWorkflow {
public function getWorkflowName() {
return 'set-config';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**set-config** [__options__] -- __name__ __value__
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: cli
Sets an arc configuration option.
Options are either user (apply to all arc commands you invoke
from the current user) or local (apply only to the current working
copy). By default, user configuration is written. Use __--local__
to write local configuration.
User values are written to '~/.arcrc' on Linux and Mac OS X, and an
undisclosed location on Windows. Local values are written to an arc
directory under either .git, .hg, or .svn as appropriate.
With __--show__, a description of supported configuration values
is shown.
EOTEXT
);
}
public function getArguments() {
return array(
'show' => array(
'help' => 'Show available configuration values.',
),
'local' => array(
'help' => 'Set a local config value instead of a user one',
),
'*' => 'argv',
);
}
public function requiresRepositoryAPI() {
return $this->getArgument('local');
}
public function run() {
if ($this->getArgument('show')) {
return $this->show();
}
$argv = $this->getArgument('argv');
if (count($argv) != 2) {
throw new ArcanistUsageException(
"Specify a key and a value, or --show.");
}
$configuration_manager = $this->getConfigurationManager();
$is_local = $this->getArgument('local');
if ($is_local) {
$config = $configuration_manager->readLocalArcConfig();
$which = 'local';
} else {
$config = $configuration_manager->readUserArcConfig();
$which = 'user';
}
$key = $argv[0];
$val = $argv[1];
$settings = new ArcanistSettings();
$old = null;
if (array_key_exists($key, $config)) {
$old = $config[$key];
}
if (!strlen($val)) {
unset($config[$key]);
if ($is_local) {
$configuration_manager->writeLocalArcConfig($config);
} else {
$configuration_manager->writeUserArcConfig($config);
}
$old = $settings->formatConfigValueForDisplay($key, $old);
if ($old === null) {
echo "Deleted key '{$key}' from {$which} config.\n";
} else {
echo "Deleted key '{$key}' from {$which} config (was {$old}).\n";
}
} else {
$val = $settings->willWriteValue($key, $val);
$config[$key] = $val;
if ($is_local) {
$configuration_manager->writeLocalArcConfig($config);
} else {
$configuration_manager->writeUserArcConfig($config);
}
$val = $settings->formatConfigValueForDisplay($key, $val);
$old = $settings->formatConfigValueForDisplay($key, $old);
if ($old === null) {
echo "Set key '{$key}' = {$val} in {$which} config.\n";
} else {
echo "Set key '{$key}' = {$val} in {$which} config (was {$old}).\n";
}
}
return 0;
}
private function show() {
$config = $this->getConfigurationManager()->readUserArcConfig();
$settings = new ArcanistSettings();
$keys = $settings->getAllKeys();
sort($keys);
foreach ($keys as $key) {
$type = $settings->getType($key);
$example = $settings->getExample($key);
$help = $settings->getHelp($key);
$value = idx($config, $key);
$value = $settings->formatConfigValueForDisplay($key, $value);
echo phutil_console_format("**__%s__** (%s)\n\n", $key, $type);
if ($example !== null) {
echo phutil_console_format(" Example: %s\n", $example);
}
if (strlen($value)) {
- echo phutil_console_format(" User Setting: %s\n", $value);
+ echo phutil_console_format(" User Setting: %s\n", $value);
}
echo "\n";
echo phutil_console_wrap($help, 4);
echo "\n\n\n";
}
return 0;
}
}
diff --git a/src/workflow/ArcanistShellCompleteWorkflow.php b/src/workflow/ArcanistShellCompleteWorkflow.php
index 266ff486..69527f1f 100644
--- a/src/workflow/ArcanistShellCompleteWorkflow.php
+++ b/src/workflow/ArcanistShellCompleteWorkflow.php
@@ -1,194 +1,194 @@
<?php
/**
* Powers shell-completion scripts.
*
* @group workflow
*/
final class ArcanistShellCompleteWorkflow extends ArcanistBaseWorkflow {
public function getWorkflowName() {
return 'shell-complete';
}
public function getCommandSynopses() {
return phutil_console_format(<<<EOTEXT
**shell-complete** __--current__ __N__ -- [__argv__]
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
Supports: bash, etc.
Implements shell completion. To use shell completion, source the
appropriate script from 'resources/shell/' in your .shellrc.
EOTEXT
);
}
public function getArguments() {
return array(
'current' => array(
'help' => 'Current term in the argument list being completed.',
'param' => 'cursor_position',
),
'*' => 'argv',
);
}
public function shouldShellComplete() {
return false;
}
public function run() {
$pos = $this->getArgument('current');
$argv = $this->getArgument('argv', array());
$argc = count($argv);
if ($pos === null) {
$pos = $argc - 1;
}
// Determine which revision control system the working copy uses, so we
// can filter out commands and flags which aren't supported. If we can't
// figure it out, just return all flags/commands.
$vcs = null;
// We have to build our own because if we requiresWorkingCopy() we'll throw
// if we aren't in a .arcconfig directory. We probably still can't do much,
// but commands can raise more detailed errors.
$working_copy = ArcanistWorkingCopyIdentity::newFromPath(getcwd());
+ $configuration_manager = $this->getConfigurationManager();
if ($working_copy->getProjectRoot()) {
- $configuration_manager = $this->getConfigurationManager();
$configuration_manager->setWorkingCopyIdentity($working_copy);
$repository_api = ArcanistRepositoryAPI::newAPIFromConfigurationManager(
$configuration_manager);
$vcs = $repository_api->getSourceControlSystemName();
}
$arc_config = $this->getArcanistConfiguration();
if ($pos == 1) {
$workflows = $arc_config->buildAllWorkflows();
$complete = array();
foreach ($workflows as $name => $workflow) {
if (!$workflow->shouldShellComplete()) {
continue;
}
$supported = $workflow->getSupportedRevisionControlSystems();
$ok = (in_array('any', $supported)) ||
(in_array($vcs, $supported));
if (!$ok) {
continue;
}
$complete[] = $name;
}
// Also permit autocompletion of "arc alias" commands.
$aliases = ArcanistAliasWorkflow::getAliases($configuration_manager);
foreach ($aliases as $key => $value) {
$complete[] = $key;
}
echo implode(' ', $complete)."\n";
return 0;
} else {
$workflow = $arc_config->buildWorkflow($argv[1]);
if (!$workflow) {
list($new_command, $new_args) = ArcanistAliasWorkflow::resolveAliases(
$argv[1],
$arc_config,
array_slice($argv, 2),
$configuration_manager);
if ($new_command) {
$workflow = $arc_config->buildWorkflow($new_command);
}
if (!$workflow) {
return 1;
} else {
$argv = array_merge(
array($argv[0]),
array($new_command),
$new_args);
}
}
$arguments = $workflow->getArguments();
$prev = idx($argv, $pos - 1, null);
if (!strncmp($prev, '--', 2)) {
$prev = substr($prev, 2);
} else {
$prev = null;
}
if ($prev !== null &&
isset($arguments[$prev]) &&
isset($arguments[$prev]['param'])) {
$type = idx($arguments[$prev], 'paramtype');
switch ($type) {
case 'file':
echo "FILE\n";
break;
case 'complete':
echo implode(' ', $workflow->getShellCompletions($argv))."\n";
break;
default:
echo "ARGUMENT\n";
break;
}
return 0;
} else {
$output = array();
foreach ($arguments as $argument => $spec) {
if ($argument == '*') {
continue;
}
if ($vcs &&
isset($spec['supports']) &&
!in_array($vcs, $spec['supports'])) {
continue;
}
$output[] = '--'.$argument;
}
$cur = idx($argv, $pos, '');
$any_match = false;
if (strlen($cur)) {
foreach ($output as $possible) {
if (!strncmp($possible, $cur, strlen($cur))) {
$any_match = true;
}
}
}
if (!$any_match && isset($arguments['*'])) {
// TODO: This is mega hacktown but something else probably breaks
// if we use a rich argument specification; fix it when we move to
// PhutilArgumentParser since everything will need to be tested then
// anyway.
if ($arguments['*'] == 'branch' && isset($repository_api)) {
$branches = $repository_api->getAllBranches();
$branches = ipull($branches, 'name');
$output = $branches;
} else {
$output = array("FILE");
}
}
echo implode(' ', $output)."\n";
return 0;
}
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Nov 24, 01:08 (1 d, 10 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
548050
Default Alt Text
(10 KB)
Attached To
Mode
R118 Arcanist - fork
Attached
Detach File
Event Timeline
Log In to Comment