@@ -38,19 +38,27 @@ 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|+ " " +| renderedArgs|+ " "
47
+ where
48
+ renderedArgs = T. intercalate " " (commandArgs c)
42
49
43
50
data GCurrentBranchData
44
51
= GCurrentBranchData
45
52
46
53
instance RenderGitCommand GCurrentBranchData where
47
- renderGC _ = " rev-parse --abbrev-ref @ "
54
+ commandArgs _ = [ " rev-parse" , " --abbrev-ref" , " @ " ]
48
55
49
56
newtype GBranchUpstreamData
50
57
= GBranchUpstreamData { branch :: Text }
51
58
52
59
instance RenderGitCommand GBranchUpstreamData where
53
- renderGC (GBranchUpstreamData branchName) = " rev-parse --abbrev-ref " +| branchName|+ " @{upstream}"
60
+ commandArgs (GBranchUpstreamData branchName) =
61
+ [" rev-parse" , " --abbrev-ref" , branchName, " @{upstream}" ]
54
62
55
63
data GLogData
56
64
= GLogData
@@ -59,7 +67,8 @@ data GLogData
59
67
, target :: Text
60
68
}
61
69
instance RenderGitCommand GLogData where
62
- renderGC (GLogData lType baseName targetName) = " log " +| logArg|+ " " +| baseName|+ " .." +| targetName|+ " "
70
+ commandArgs (GLogData lType baseName targetName) =
71
+ [" log " , logArg, " " +| baseName|+ " .." +| targetName|+ " " ]
63
72
where
64
73
logArg :: Text
65
74
logArg = case lType of
@@ -69,7 +78,7 @@ newtype GStatusData
69
78
= GStatusData { statusType :: StatusType }
70
79
71
80
instance RenderGitCommand GStatusData where
72
- renderGC (GStatusData sType) = " status " +| statusFormat|+ " "
81
+ commandArgs (GStatusData sType) = [ " status" , statusFormat]
73
82
where
74
83
statusFormat :: Text
75
84
statusFormat = case sType of
@@ -78,7 +87,7 @@ instance RenderGitCommand GStatusData where
78
87
data GStashListData
79
88
= GStashListData
80
89
instance RenderGitCommand GStashListData where
81
- renderGC _ = " stash list"
90
+ commandArgs _ = [ " stash" , " list" ]
82
91
83
92
data GReadConfigData
84
93
= GReadConfigData
@@ -87,7 +96,7 @@ data GReadConfigData
87
96
}
88
97
89
98
instance RenderGitCommand GReadConfigData where
90
- renderGC (GReadConfigData cScope cName) = " config " +| scopeText|+ " --get " +| cName|+ " "
99
+ commandArgs (GReadConfigData cScope cName) = [ " config" , scopeText, " --get" , cName]
91
100
where
92
101
scopeText :: Text
93
102
scopeText = case cScope of
@@ -103,7 +112,7 @@ data GSetConfigData
103
112
}
104
113
105
114
instance RenderGitCommand GSetConfigData where
106
- renderGC (GSetConfigData cScope cName cValue) = " config " +| scopeText|+ " " +| cName|+ " " +| cValue|+ " "
115
+ commandArgs (GSetConfigData cScope cName cValue) = [ " config" , scopeText, cName, " \" " +| cValue|+ " \" " ]
107
116
where
108
117
scopeText :: Text
109
118
scopeText = case cScope of
@@ -118,7 +127,7 @@ data GUnsetConfigData
118
127
}
119
128
120
129
instance RenderGitCommand GUnsetConfigData where
121
- renderGC (GUnsetConfigData cScope cName) = " config " +| scopeText|+ " --unset " +| cName|+ " "
130
+ commandArgs (GUnsetConfigData cScope cName) = [ " config" , scopeText, " --unset" , cName]
122
131
where
123
132
scopeText :: Text
124
133
scopeText = case cScope of
@@ -130,7 +139,8 @@ newtype GAliasesToRemoveData
130
139
= GAliasesToRemoveData { scope :: ConfigScope }
131
140
132
141
instance RenderGitCommand GAliasesToRemoveData where
133
- renderGC (GAliasesToRemoveData cScope) = " config " +| scopeText|+ " --name-only --get-regexp \" ^alias.\" \" ^elegant ([-a-z]+)$\" "
142
+ commandArgs (GAliasesToRemoveData cScope) =
143
+ [" config" , scopeText, " --name-only" , " --get-regexp" , " \" ^alias.\" " , " \" ^elegant ([-a-z]+)$\" " ]
134
144
where
135
145
scopeText :: Text
136
146
scopeText = case cScope of
@@ -246,7 +256,7 @@ print content = liftF $ PrintText content ()
246
256
-- Derived actions
247
257
248
258
formatGitCommand :: (RenderGitCommand gc , MonadFree GitF m ) => gc -> m Text
249
- formatGitCommand gc = formatCommand (" git " +| renderGC gc|+ " " )
259
+ formatGitCommand gc = formatCommand (renderGC gc)
250
260
251
261
setConfigVerbose :: MonadFree GitF m => ConfigScope -> Text -> Text -> m ()
252
262
setConfigVerbose cScope cName cValue = do
0 commit comments