You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
diff--gita/internal/command/root.gob/internal/command/root.go
index 787e9e8..6f382eb100644---a/internal/command/root.go+++b/internal/command/root.go
@@ -6,6+6,7 @@ import (
"os""path/filepath""runtime/pprof"+"time""github.com/fatih/color""github.com/spf13/cobra"
@@ -25,6+26,7 @@ varrootCmd=&cobra.Command{
varverboseFlagboolvarcpuProfilingFlagboolvarnoColorFlagbool+vartimeoutFlag time.DurationvardefCPUProfFile=filepath.Join(os.TempDir(), "baur-cpu.prof")
@@ -53,6+55,11 @@ funcinitSb(_*cobra.Command, _ []string) {
log.Fatalln(err)
}
}
++iftimeoutFlag!=0 {
+// nolint:govet // loosing the cancelFn is fine here, need to run it+ctx, _=context.WithTimeout(ctx, timeoutFlag)
+ }
}
// Execute parses commandline flags and execute their actions
@@ -66,6+73,8 @@ funcExecute() {
rootCmd.PersistentFlags().BoolVar(&cpuProfilingFlag, "cpu-prof", false,
fmt.Sprintf("enable cpu profiling, result is written to %q", defCPUProfFile))
rootCmd.PersistentFlags().BoolVar(&noColorFlag, "no-color", false, "disable color output")
+rootCmd.PersistentFlags().DurationVar(&timeoutFlag, "timeout", 0,
+"Time limit for the command, when it is exceeded baur exits with an error")
iferr:=rootCmd.Execute(); err!=nil {
log.Fatalln(err)
The text was updated successfully, but these errors were encountered:
Add a --timeout parameter that causes the executed command to exit with an error when it's exceeded.
Requires: #158
Diff to add a timeout parameter for all commands:
The text was updated successfully, but these errors were encountered: