Skip to content

Commit 50fc17d

Browse files
committed
Implement config.get
1 parent cb913c0 commit 50fc17d

File tree

9 files changed

+70
-10
lines changed

9 files changed

+70
-10
lines changed

unison-cli/src/Unison/Codebase/Editor/HandleInput.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import Unison.Codebase.Editor.HandleInput.BranchRename (handleBranchRename)
5050
import Unison.Codebase.Editor.HandleInput.BranchSquash (handleBranchSquash)
5151
import Unison.Codebase.Editor.HandleInput.Branches (handleBranches)
5252
import Unison.Codebase.Editor.HandleInput.Cancel (handleCancel)
53-
import Unison.Codebase.Editor.HandleInput.ConfigSet (handleConfigSet)
53+
import Unison.Codebase.Editor.HandleInput.Config (handleConfigGet, handleConfigSet)
5454
import Unison.Codebase.Editor.HandleInput.DebugDefinition qualified as DebugDefinition
5555
import Unison.Codebase.Editor.HandleInput.DebugFoldRanges qualified as DebugFoldRanges
5656
import Unison.Codebase.Editor.HandleInput.DebugSynhashTerm (handleDebugSynhashTerm)
@@ -719,6 +719,7 @@ loop e = do
719719
BranchRenameI name -> handleBranchRename name
720720
BranchesI name -> handleBranches name
721721
CloneI remoteNames localNames -> handleClone remoteNames localNames
722+
ConfigGetI key -> handleConfigGet key
722723
ConfigSetI key value -> handleConfigSet key value
723724
BranchSquashI branchToSquash destBranch -> handleBranchSquash branchToSquash destBranch
724725
ReleaseDraftI semver -> handleReleaseDraft semver
@@ -802,6 +803,7 @@ inputDescription input =
802803
ClearI {} -> wat
803804
CloneI {} -> wat
804805
ConfigSetI {} -> wat
806+
ConfigGetI {} -> wat
805807
CreateMessage {} -> wat
806808
DebugClearWatchI {} -> wat
807809
DebugDoctorI {} -> wat
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
module Unison.Codebase.Editor.HandleInput.ConfigSet (handleConfigSet) where
1+
module Unison.Codebase.Editor.HandleInput.Config (handleConfigSet, handleConfigGet) where
22

33
import U.Codebase.Config (ConfigKey)
44
import U.Codebase.Sqlite.Queries qualified as Q
55
import Unison.Cli.Monad (Cli)
66
import Unison.Cli.Monad qualified as Cli
7+
import Unison.Codebase.Editor.Output (Output (..))
78
import Unison.Prelude
89

910
handleConfigSet :: ConfigKey -> Text -> Cli ()
1011
handleConfigSet key value = do
1112
Cli.runTransaction $ Q.setConfigValue key value
13+
14+
handleConfigGet :: ConfigKey -> Cli ()
15+
handleConfigGet key = do
16+
mayValue <- Cli.runTransaction $ Q.getConfigValue key
17+
Cli.respond $ ConfigValueGet key mayValue

unison-cli/src/Unison/Codebase/Editor/Input.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ data Input
249249
| BranchSquashI (ProjectAndBranch (Maybe ProjectName) ProjectBranchName) (ProjectAndBranch (Maybe ProjectName) ProjectBranchName)
250250
| CancelI
251251
| ConfigSetI ConfigKey Text
252+
| ConfigGetI ConfigKey
252253
deriving (Eq, Show)
253254

254255
-- | The source of a `branch` command: what to make the new branch from.

unison-cli/src/Unison/Codebase/Editor/Output.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import Servant.Client qualified as Servant (ClientError)
2727
import System.Console.Haskeline qualified as Completion
2828
import System.Exit (ExitCode)
2929
import U.Codebase.Branch.Diff (NameChanges)
30+
import U.Codebase.Config (ConfigKey)
3031
import U.Codebase.HashTags (CausalHash)
3132
import U.Codebase.Sqlite.HistoryComment (HistoryComment)
3233
import U.Codebase.Sqlite.Project qualified as Sqlite
@@ -458,6 +459,7 @@ data Output
458459
| CommentedSuccessfully
459460
| CommentAborted
460461
| AuthorNameRequired
462+
| ConfigValueGet ConfigKey (Maybe Text)
461463

462464
data MoreEntriesThanShown = MoreEntriesThanShown | AllEntriesShown
463465
deriving (Eq, Show)
@@ -703,6 +705,7 @@ isFailure o = case o of
703705
CommentedSuccessfully {} -> False
704706
CommentAborted {} -> True
705707
AuthorNameRequired {} -> True
708+
ConfigValueGet {} -> False
706709

707710
isNumberedFailure :: NumberedOutput -> Bool
708711
isNumberedFailure = \case

unison-cli/src/Unison/CommandLine/InputPatterns.hs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module Unison.CommandLine.InputPatterns
1616
clear,
1717
clone,
1818
configSet,
19+
configGet,
1920
createAuthor,
2021
debugClearWatchCache,
2122
debugDoctor,
@@ -2478,6 +2479,33 @@ configSet =
24782479
args -> wrongArgsLength "exactly two arguments" args
24792480
}
24802481

2482+
configGet :: InputPattern
2483+
configGet =
2484+
InputPattern
2485+
{ patternName = "config.get",
2486+
aliases = [],
2487+
visibility = I.Visible,
2488+
params = Parameters [("key", configKeyArg), ("value", noCompletionsArg)] $ Optional [] Nothing,
2489+
help =
2490+
P.lines
2491+
[ P.wrap $
2492+
"Gets the value of the provided configuration key. E.g.",
2493+
"",
2494+
(makeExample configGet [P.text $ Config.keyToText Config.AuthorNameKey]),
2495+
"",
2496+
P.hang
2497+
"Configuration options include:"
2498+
(P.wrap . P.text $ Text.intercalate ", " $ Config.allKeysText)
2499+
],
2500+
parse = \case
2501+
[key] -> do
2502+
key' <- unsupportedStructuredArgument configSet "a config key" key
2503+
case Config.keyFromText (Text.pack key') of
2504+
Nothing -> Left . P.text $ "I don't recognize that config key. Available keys are: " <> Text.intercalate ", " Config.allKeysText
2505+
Just pkey -> Right $ Input.ConfigGetI pkey
2506+
args -> wrongArgsLength "exactly one argument" args
2507+
}
2508+
24812509
edit :: InputPattern
24822510
edit =
24832511
InputPattern
@@ -3658,6 +3686,7 @@ validInputs =
36583686
cd,
36593687
clear,
36603688
clone,
3689+
configGet,
36613690
configSet,
36623691
createAuthor,
36633692
debugAliasTermForce,

unison-cli/src/Unison/CommandLine/OutputMessages.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ import Unison.Var (Var)
164164
import Unison.Var qualified as Var
165165
import Unison.WatchKind qualified as WK
166166
import Witch (unsafeFrom)
167+
import qualified U.Codebase.Config as Config
167168

168169
reportBugURL :: Pretty
169170
reportBugURL = "https://github.com/unisonweb/unison/issues/new"
@@ -2372,6 +2373,16 @@ notifyUser dir issueFn = \case
23722373
[ "You can do so with: ",
23732374
IP.makeExampleNoBackticks IP.configSet ["author.name", "<your name>"]
23742375
]
2376+
ConfigValueGet key value ->
2377+
case value of
2378+
Nothing -> pure $
2379+
P.wrap $
2380+
P.text (Config.keyToText key)
2381+
<> " is unset"
2382+
Just value ->
2383+
pure $ P.wrap $
2384+
P.text (Config.keyToText key)
2385+
<> " = " <> P.text value
23752386
where
23762387
iveCreatedATemporaryBranch scratchFile =
23772388
P.wrap $

unison-cli/unison-cli.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ library
5353
Unison.Codebase.Editor.HandleInput.BranchRename
5454
Unison.Codebase.Editor.HandleInput.BranchSquash
5555
Unison.Codebase.Editor.HandleInput.Cancel
56-
Unison.Codebase.Editor.HandleInput.ConfigSet
56+
Unison.Codebase.Editor.HandleInput.Config
5757
Unison.Codebase.Editor.HandleInput.DebugDefinition
5858
Unison.Codebase.Editor.HandleInput.DebugFoldRanges
5959
Unison.Codebase.Editor.HandleInput.DebugSynhashTerm

unison-src/transcripts-using-base/serial-test-05.output.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mkTestCase = do
2121
2222
+ f : (Nat, Nat, Nat) -> Nat
2323
+ g : Map Nat ((Nat, Nat, Nat) ->{g} Nat) ->{g} Text
24-
+ m : Map Nat ((Nat, Nat, Nat) ->{g} Nat)
24+
+ m : Map Nat ((Nat, Nat, Nat) ->{g1, g} Nat)
2525
+ mkTestCase : '{IO, Exception} ()
2626
2727
Run `update` to apply these changes to your codebase.

unison-src/transcripts/idempotent/help.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919
alias.type
2020
`alias.type Foo Bar` introduces `Bar` with the same definition as `Foo`.
2121
22-
annotate
23-
`annotate` Annotates the head of the current branch.
24-
`annotate /main` Annotates the current head of the `main`
25-
branch.
26-
2722
api
2823
`api` provides details about the API.
2924
@@ -99,11 +94,18 @@
9994
Said execution will have the effect of
10095
running `!main`.
10196
97+
config.get
98+
Gets the value of the provided configuration key. E.g.
99+
100+
`config.get author.name`
101+
102+
Configuration options include: author.name
103+
102104
config.set
103105
The `config.set` command sets the configuration key to the
104106
provided value. E.g.
105107
106-
`config.set author.name Author Name`
108+
`config.set author.name "Author Name"`
107109
108110
Configuration options include: author.name
109111
@@ -510,6 +512,12 @@
510512
namespace with the given hash.
511513
The full hash must be provided.
512514
515+
history.comment (or comment, comment.history)
516+
`history.comment` Creates a comment after the head of
517+
the current branch.
518+
`history.comment /main` Creates a comment after the head of
519+
the `main` branch.
520+
513521
io.test (or test.io)
514522
`io.test mytest` Runs `!mytest`, where `mytest` is a delayed
515523
test that can use the `IO` and `Exception`

0 commit comments

Comments
 (0)