Skip to content

Commit 890f1ee

Browse files
committed
wrap the original cli function instead of replacing it
1 parent d66fa8c commit 890f1ee

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

cmd/main.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,16 @@ DEFAULT CONFIGURATION:
4646
}
4747

4848
func prepareSubcommandWithGlobalFlags(command *cli.Command) {
49-
command.Before = prepareWorkPathAndCustomConf()
49+
command.Before = prepareWorkPathAndCustomConf(command.Before)
5050
}
5151

5252
// prepareWorkPathAndCustomConf wraps the Action to prepare the work path and custom config
53-
func prepareWorkPathAndCustomConf() cli.BeforeFunc {
53+
func prepareWorkPathAndCustomConf(original cli.BeforeFunc) cli.BeforeFunc {
54+
if original == nil {
55+
original = func(ctx context.Context, c *cli.Command) (context.Context, error) {
56+
return ctx, nil
57+
}
58+
}
5459
return func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
5560
var args setting.ArgWorkPathAndCustomConf
5661
if cmd.IsSet("work-path") {
@@ -63,7 +68,7 @@ func prepareWorkPathAndCustomConf() cli.BeforeFunc {
6368
args.CustomConf = cmd.String("config")
6469
}
6570
setting.InitWorkPathAndCommonConfig(os.Getenv, args)
66-
return ctx, nil
71+
return original(ctx, cmd)
6772
}
6873
}
6974

0 commit comments

Comments
 (0)