Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F7187924
ArcanistSetConfigWorkflow.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
ArcanistSetConfigWorkflow.php
View Options
<?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** [__options__] -- __name__ __value__
EOTEXT
);
}
public
function
getCommandHelp
()
{
return
phutil_console_format
(
<<<EOTEXT
Supports: cli
Sets an arc configuration option.
Options are either global (apply to all arc commands you invoke
from the current user) or local (apply only to the current working
copy). By default, global configuration is written. Use __--local__
to write local configuration.
Global 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 global 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."
);
}
$is_local
=
$this
->
getArgument
(
'local'
);
if
(
$is_local
)
{
$config
=
$this
->
readLocalArcConfig
();
$which
=
'local'
;
}
else
{
$config
=
self
::
readGlobalArcConfig
();
$which
=
'global'
;
}
$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
)
{
$this
->
writeLocalArcConfig
(
$config
);
}
else
{
self
::
writeGlobalArcConfig
(
$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
)
{
$this
->
writeLocalArcConfig
(
$config
);
}
else
{
self
::
writeGlobalArcConfig
(
$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
=
self
::
readGlobalArcConfig
();
$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
(
" Global Setting: %s
\n
"
,
$value
);
}
echo
"
\n
"
;
echo
phutil_console_wrap
(
$help
,
4
);
echo
"
\n\n\n
"
;
}
return
0
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, Jul 8, 07:42 (14 h, 38 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
806658
Default Alt Text
ArcanistSetConfigWorkflow.php (4 KB)
Attached To
Mode
R118 Arcanist - fork
Attached
Detach File
Event Timeline
Log In to Comment