Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
ghcup-hs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Haskell
ghcup-hs
Commits
2a11e85a
Verified
Commit
2a11e85a
authored
3 years ago
by
Julian Ospald
Browse files
Options
Downloads
Patches
Plain Diff
Allow to specify config value as JSON
parent
69df100b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!214
Allow to specify config value as JSON
Pipeline
#42661
passed
3 years ago
Stage: checks
Stage: quick-test
Stage: test
Stage: expensive-test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/ghcup/GHCup/OptParse/Config.hs
+37
-19
37 additions, 19 deletions
app/ghcup/GHCup/OptParse/Config.hs
with
37 additions
and
19 deletions
app/ghcup/GHCup/OptParse/Config.hs
+
37
−
19
View file @
2a11e85a
...
...
@@ -28,6 +28,7 @@ import Data.Functor
import
Data.Maybe
import
Haskus.Utils.Variant.Excepts
import
Options.Applicative
hiding
(
style
)
import
Options.Applicative.Help.Pretty
(
text
)
import
Prelude
hiding
(
appendFile
)
import
System.Exit
...
...
@@ -46,7 +47,7 @@ import Control.Exception.Safe (MonadMask)
data
ConfigCommand
=
ShowConfig
|
SetConfig
String
String
|
SetConfig
String
(
Maybe
String
)
|
InitConfig
...
...
@@ -67,8 +68,8 @@ configP = subparser
where
initP
=
info
(
pure
InitConfig
)
(
progDesc
"Write default config to ~/.ghcup/config.yaml"
)
showP
=
info
(
pure
ShowConfig
)
(
progDesc
"Show current config (default)"
)
setP
=
info
argsP
(
progDesc
"Set config KEY to VALUE
"
)
argsP
=
SetConfig
<$>
argument
str
(
metavar
"KEY"
)
<*>
argument
str
(
metavar
"VALUE"
)
setP
=
info
argsP
(
progDesc
"Set config KEY to VALUE
(or specify as single json value)"
<>
footerDoc
(
Just
$
text
configSetFooter
)
)
argsP
=
SetConfig
<$>
argument
str
(
metavar
"
<JSON_VALUE | YAML_
KEY
>
"
)
<*>
optional
(
argument
str
(
metavar
"
YAML_
VALUE"
)
)
...
...
@@ -88,7 +89,19 @@ configFooter = [s|Examples:
ghcup config init
# set <key> <value> configuration pair
ghcup config <key> <value>
|]
ghcup config set <key> <value>
|]
configSetFooter
::
String
configSetFooter
=
[
s
|
Examples:
# disable caching
ghcup config set cache false
# switch downloader to wget
ghcup config set downloader Wget
# set mirror for ghcup metadata
ghcup config set '{url-source: { OwnSource: "<url>"}}'
|]
...
...
@@ -147,22 +160,27 @@ config configCommand settings keybindings runLogger = case configCommand of
liftIO
$
putStrLn
$
formatConfig
$
fromSettings
settings
(
Just
keybindings
)
pure
ExitSuccess
(
SetConfig
k
v
)
->
do
(
SetConfig
k
(
Just
v
)
)
->
case
v
of
""
->
do
runLogger
$
logError
"Empty values are not allowed"
pure
$
ExitFailure
55
_
->
do
r
<-
runE
@
'
[
JSONError
]
$
do
settings'
<-
updateSettings
(
UTF8
.
fromString
(
k
<>
": "
<>
v
<>
"
\n
"
))
settings
path
<-
liftIO
getConfigFilePath
liftIO
$
writeFile
path
$
formatConfig
$
fromSettings
settings'
(
Just
keybindings
)
lift
$
runLogger
$
logDebug
$
T
.
pack
$
show
settings'
pure
()
case
r
of
VRight
_
->
pure
ExitSuccess
VLeft
(
V
(
JSONDecodeError
e
))
->
do
runLogger
$
logError
$
"Error decoding config: "
<>
T
.
pack
e
pure
$
ExitFailure
65
VLeft
_
->
pure
$
ExitFailure
65
_
->
doConfig
(
k
<>
": "
<>
v
<>
"
\n
"
)
(
SetConfig
json
Nothing
)
->
doConfig
json
where
doConfig
val
=
do
r
<-
runE
@
'
[
JSONError
]
$
do
settings'
<-
updateSettings
(
UTF8
.
fromString
val
)
settings
path
<-
liftIO
getConfigFilePath
liftIO
$
writeFile
path
$
formatConfig
$
fromSettings
settings'
(
Just
keybindings
)
lift
$
runLogger
$
logDebug
$
T
.
pack
$
show
settings'
pure
()
case
r
of
VRight
_
->
pure
ExitSuccess
VLeft
(
V
(
JSONDecodeError
e
))
->
do
runLogger
$
logError
$
"Error decoding config: "
<>
T
.
pack
e
pure
$
ExitFailure
65
VLeft
_
->
pure
$
ExitFailure
65
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment