@@ -38,19 +38,24 @@ import Universum hiding (print)
38
38
39
39
-- TODO: maybe, cover with tests
40
40
class RenderGitCommand c where
41
- renderGC :: c -> Text
41
+ commandArgs :: c -> Text
42
+ toolName :: c -> Text
43
+ toolName _ = " git"
44
+
45
+ renderGC :: RenderGitCommand c => c -> Text
46
+ renderGC c = toolName c|+ " " +| commandArgs c|+ " "
42
47
43
48
data GCurrentBranchData
44
49
= GCurrentBranchData
45
50
46
51
instance RenderGitCommand GCurrentBranchData where
47
- renderGC _ = " rev-parse --abbrev-ref @"
52
+ commandArgs _ = " rev-parse --abbrev-ref @"
48
53
49
54
newtype GBranchUpstreamData
50
55
= GBranchUpstreamData { branch :: Text }
51
56
52
57
instance RenderGitCommand GBranchUpstreamData where
53
- renderGC (GBranchUpstreamData branchName) = " rev-parse --abbrev-ref " +| branchName|+ " @{upstream}"
58
+ commandArgs (GBranchUpstreamData branchName) = " rev-parse --abbrev-ref " +| branchName|+ " @{upstream}"
54
59
55
60
data GLogData
56
61
= GLogData
@@ -59,7 +64,7 @@ data GLogData
59
64
, target :: Text
60
65
}
61
66
instance RenderGitCommand GLogData where
62
- renderGC (GLogData lType baseName targetName) = " log " +| logArg|+ " " +| baseName|+ " .." +| targetName|+ " "
67
+ commandArgs (GLogData lType baseName targetName) = " log " +| logArg|+ " " +| baseName|+ " .." +| targetName|+ " "
63
68
where
64
69
logArg :: Text
65
70
logArg = case lType of
@@ -69,7 +74,7 @@ newtype GStatusData
69
74
= GStatusData { statusType :: StatusType }
70
75
71
76
instance RenderGitCommand GStatusData where
72
- renderGC (GStatusData sType) = " status " +| statusFormat|+ " "
77
+ commandArgs (GStatusData sType) = " status " +| statusFormat|+ " "
73
78
where
74
79
statusFormat :: Text
75
80
statusFormat = case sType of
@@ -78,7 +83,7 @@ instance RenderGitCommand GStatusData where
78
83
data GStashListData
79
84
= GStashListData
80
85
instance RenderGitCommand GStashListData where
81
- renderGC _ = " stash list"
86
+ commandArgs _ = " stash list"
82
87
83
88
data GReadConfigData
84
89
= GReadConfigData
@@ -87,7 +92,7 @@ data GReadConfigData
87
92
}
88
93
89
94
instance RenderGitCommand GReadConfigData where
90
- renderGC (GReadConfigData cScope cName) = " config " +| scopeText|+ " --get " +| cName|+ " "
95
+ commandArgs (GReadConfigData cScope cName) = " config " +| scopeText|+ " --get " +| cName|+ " "
91
96
where
92
97
scopeText :: Text
93
98
scopeText = case cScope of
@@ -103,7 +108,7 @@ data GSetConfigData
103
108
}
104
109
105
110
instance RenderGitCommand GSetConfigData where
106
- renderGC (GSetConfigData cScope cName cValue) = " config " +| scopeText|+ " " +| cName|+ " " +| cValue|+ " "
111
+ commandArgs (GSetConfigData cScope cName cValue) = " config " +| scopeText|+ " " +| cName|+ " \" " +| cValue|+ " \ ""
107
112
where
108
113
scopeText :: Text
109
114
scopeText = case cScope of
@@ -118,7 +123,7 @@ data GUnsetConfigData
118
123
}
119
124
120
125
instance RenderGitCommand GUnsetConfigData where
121
- renderGC (GUnsetConfigData cScope cName) = " config " +| scopeText|+ " --unset " +| cName|+ " "
126
+ commandArgs (GUnsetConfigData cScope cName) = " config " +| scopeText|+ " --unset " +| cName|+ " "
122
127
where
123
128
scopeText :: Text
124
129
scopeText = case cScope of
@@ -130,14 +135,21 @@ newtype GAliasesToRemoveData
130
135
= GAliasesToRemoveData { scope :: ConfigScope }
131
136
132
137
instance RenderGitCommand GAliasesToRemoveData where
133
- renderGC (GAliasesToRemoveData cScope) = " config " +| scopeText|+ " --name-only --get-regexp \" ^alias.\" \" ^elegant ([-a-z]+)$\" "
138
+ commandArgs (GAliasesToRemoveData cScope) = " config " +| scopeText|+ " --name-only --get-regexp \" ^alias.\" \" ^elegant ([-a-z]+)$\" "
134
139
where
135
140
scopeText :: Text
136
141
scopeText = case cScope of
137
142
GlobalConfig -> " --global"
138
143
LocalConfig -> " --local"
139
144
AutoConfig -> " "
140
145
146
+ newtype GGPGKeyListData
147
+ = GGPGKeyListData { email :: Text }
148
+
149
+ instance RenderGitCommand GGPGKeyListData where
150
+ toolName _ = " gpg"
151
+ commandArgs (GGPGKeyListData gEmail) = " --list-secret-keys --keyid-format long " +| gEmail|+ " "
152
+
141
153
-- | The declaration of all posible actions we can do in the git action.
142
154
--
143
155
-- This describes the data of the action, and whether it can return any value
@@ -155,6 +167,7 @@ data GitF a
155
167
| AliasesToRemove GAliasesToRemoveData (Maybe (NonEmpty Text ) -> a )
156
168
| SetConfig GSetConfigData a
157
169
| UnsetConfig GUnsetConfigData a
170
+ | GPGListKeys GGPGKeyListData (Maybe (NonEmpty Text ) -> a )
158
171
| Prompt Text (Maybe Text ) (Text -> a )
159
172
| FormatInfo Text (Text -> a )
160
173
| FormatCommand Text (Text -> a )
@@ -231,6 +244,9 @@ setConfig cScope cName cValue = liftF $ SetConfig (GSetConfigData cScope cName c
231
244
unsetConfig :: MonadFree GitF m => ConfigScope -> Text -> m ()
232
245
unsetConfig cScope cName = liftF $ UnsetConfig (GUnsetConfigData cScope cName) ()
233
246
247
+ gpgListKeys :: MonadFree GitF m => Text -> m (Maybe (NonEmpty Text ))
248
+ gpgListKeys gEmail = liftF $ GPGListKeys (GGPGKeyListData gEmail) id
249
+
234
250
promptDefault :: MonadFree GitF m => Text -> Maybe Text -> m Text
235
251
promptDefault pText pDefault = liftF $ Prompt pText pDefault id
236
252
@@ -246,7 +262,7 @@ print content = liftF $ PrintText content ()
246
262
-- Derived actions
247
263
248
264
formatGitCommand :: (RenderGitCommand gc , MonadFree GitF m ) => gc -> m Text
249
- formatGitCommand gc = formatCommand (" git " +| renderGC gc|+ " " )
265
+ formatGitCommand gc = formatCommand (renderGC gc)
250
266
251
267
setConfigVerbose :: MonadFree GitF m => ConfigScope -> Text -> Text -> m ()
252
268
setConfigVerbose cScope cName cValue = do
@@ -258,6 +274,12 @@ unsetConfigVerbose cScope cName = do
258
274
unsetConfig cScope cName
259
275
print =<< formatGitCommand (GUnsetConfigData cScope cName)
260
276
277
+ gpgListKeysVerbose :: MonadFree GitF m => Text -> m (Maybe (NonEmpty Text ))
278
+ gpgListKeysVerbose gEmail = do
279
+ gpgKeys <- gpgListKeys gEmail
280
+ print =<< formatGitCommand (GGPGKeyListData gEmail)
281
+ return gpgKeys
282
+
261
283
freshestDefaultBranch :: MonadFree GitF m => m Text
262
284
freshestDefaultBranch = do
263
285
-- TODO: Port bash logic
0 commit comments