Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbd08b11

Browse files
authored
Merge pull request#197 from remi-dupre/noinit-commands
main: do not initialize for version & completion commands
2 parents5d60af9 +ee429bb commitbd08b11

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

‎cmd/dstask/main.go

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,43 @@ import (
1010
)
1111

1212
funcmain() {
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-
iflen(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+
switchquery.Cmd {
21+
casedstask.CMD_HELP:
1722
dstask.CommandHelp(os.Args)
23+
24+
casedstask.CMD_VERSION:
25+
dstask.CommandVersion()
26+
27+
casedstask.CMD_PRINT_BASH_COMPLETION:
28+
fmt.Print(completions.Bash)
29+
30+
casedstask.CMD_PRINT_ZSH_COMPLETION:
31+
fmt.Print(completions.Zsh)
32+
33+
casedstask.CMD_PRINT_FISH_COMPLETION:
34+
fmt.Print(completions.Fish)
35+
36+
default:
37+
noInitCommand=false
1838
}
1939

40+
ifnoInitCommand {
41+
return
42+
}
43+
2044
conf:=dstask.NewConfig()
2145
dstask.EnsureRepoExists(conf.Repo)
2246

2347
// Load state for getting and setting ctx
2448
state:=dstask.LoadState(conf.StateFile)
2549
ctx:=state.Context
26-
query:=dstask.ParseQuery(os.Args[1:]...)
2750

2851
// Check if we have a context override.
2952
ifconf.CtxFromEnvVar!="" {
@@ -159,20 +182,9 @@ func main() {
159182
dstask.ExitFail(err.Error())
160183
}
161184

162-
casedstask.CMD_VERSION:
163-
dstask.CommandVersion()
164-
165185
casedstask.CMD_COMPLETIONS:
166186
completions.Completions(conf,os.Args,ctx)
167187

168-
casedstask.CMD_PRINT_BASH_COMPLETION:
169-
fmt.Print(completions.Bash)
170-
171-
casedstask.CMD_PRINT_ZSH_COMPLETION:
172-
fmt.Print(completions.Zsh)
173-
174-
casedstask.CMD_PRINT_FISH_COMPLETION:
175-
fmt.Print(completions.Fish)
176188
default:
177189
panic("this should never happen?")
178190
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp