Compare commits
1 Commits
5205ddf094
...
feat/timeo
| Author | SHA1 | Date | |
|---|---|---|---|
| 2abebfd01b |
@ -1,8 +1,11 @@
|
||||
package cmd
|
||||
|
||||
const DefaultRequestTimeout uint = 30
|
||||
|
||||
type AppConfig struct {
|
||||
OutputVerbose bool
|
||||
OutputFormatter string
|
||||
OutputOrderReverse bool
|
||||
PrintConfig bool
|
||||
RequestTimeoutSeconds uint
|
||||
}
|
||||
|
||||
@ -34,6 +34,7 @@ func initRootCmd() {
|
||||
rootCmd.PersistentFlags().StringVarP(&appConfig.OutputFormatter, "output", "o", "table", "Set output format")
|
||||
rootCmd.PersistentFlags().BoolVar(&appConfig.OutputOrderReverse, "reverse", false, "Reverses output item order")
|
||||
rootCmd.PersistentFlags().BoolVar(&appConfig.PrintConfig, "print-config", false, "Enable printing the application config")
|
||||
rootCmd.PersistentFlags().UintVar(&appConfig.RequestTimeoutSeconds, "timeout", DefaultRequestTimeout, "Set the request timeout in seconds")
|
||||
|
||||
logger := jlog.New(slog.LevelDebug)
|
||||
ctx := jlog.ContextWith(context.Background(), logger)
|
||||
|
||||
@ -8,6 +8,7 @@ import (
|
||||
"os"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.bissendorf.co/bissendorf/unifood/m/v2/core/interfaces"
|
||||
"git.bissendorf.co/bissendorf/unifood/m/v2/core/interfaces/params"
|
||||
@ -92,6 +93,8 @@ func getVerbs(ctx context.Context, config *AppConfig) (commands []*cobra.Command
|
||||
}
|
||||
logger := jlog.New(logLevel)
|
||||
ctx := jlog.ContextWith(context.Background(), logger)
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Duration(config.RequestTimeoutSeconds)*time.Second)
|
||||
defer cancel()
|
||||
|
||||
// Print config
|
||||
if config.PrintConfig {
|
||||
|
||||
Reference in New Issue
Block a user