@@ -10,20 +10,43 @@ import (
10
10
)
11
11
12
12
func main () {
13
- // special case: allow users to run the help command without requiring
14
- // initialisation. Other commands are handled in the below switch statement
15
- // after initialisation.
16
- if len (os .Args )> 1 && os .Args [1 ]== dstask .CMD_HELP {
13
+ query := dstask .ParseQuery (os .Args [1 :]... )
14
+
15
+ // It will remain true if we handle a command that doesn't require
16
+ // initialisation
17
+ noInitCommand := true
18
+
19
+ // Handle commands that don't require initialisation
20
+ switch query .Cmd {
21
+ case dstask .CMD_HELP :
17
22
dstask .CommandHelp (os .Args )
23
+
24
+ case dstask .CMD_VERSION :
25
+ dstask .CommandVersion ()
26
+
27
+ case dstask .CMD_PRINT_BASH_COMPLETION :
28
+ fmt .Print (completions .Bash )
29
+
30
+ case dstask .CMD_PRINT_ZSH_COMPLETION :
31
+ fmt .Print (completions .Zsh )
32
+
33
+ case dstask .CMD_PRINT_FISH_COMPLETION :
34
+ fmt .Print (completions .Fish )
35
+
36
+ default :
37
+ noInitCommand = false
18
38
}
19
39
40
+ if noInitCommand {
41
+ return
42
+ }
43
+
20
44
conf := dstask .NewConfig ()
21
45
dstask .EnsureRepoExists (conf .Repo )
22
46
23
47
// Load state for getting and setting ctx
24
48
state := dstask .LoadState (conf .StateFile )
25
49
ctx := state .Context
26
- query := dstask .ParseQuery (os .Args [1 :]... )
27
50
28
51
// Check if we have a context override.
29
52
if conf .CtxFromEnvVar != "" {
@@ -159,20 +182,9 @@ func main() {
159
182
dstask .ExitFail (err .Error ())
160
183
}
161
184
162
- case dstask .CMD_VERSION :
163
- dstask .CommandVersion ()
164
-
165
185
case dstask .CMD_COMPLETIONS :
166
186
completions .Completions (conf ,os .Args ,ctx )
167
187
168
- case dstask .CMD_PRINT_BASH_COMPLETION :
169
- fmt .Print (completions .Bash )
170
-
171
- case dstask .CMD_PRINT_ZSH_COMPLETION :
172
- fmt .Print (completions .Zsh )
173
-
174
- case dstask .CMD_PRINT_FISH_COMPLETION :
175
- fmt .Print (completions .Fish )
176
188
default :
177
189
panic ("this should never happen?" )
178
190
}