MCPcopy Index your code
hub / github.com/cloudquery/cloudquery / executeRootCmdWithContext

Function executeRootCmdWithContext

cli/main.go:18–45  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16)
17
18func executeRootCmdWithContext() error {
19 // trap Ctrl+C and other signals, then call cancel on the context
20 ctx, cancel := context.WithCancel(context.Background())
21 c := make(chan os.Signal, 1)
22 signal.Notify(c, os.Interrupt, syscall.SIGTERM)
23 defer func() {
24 signal.Stop(c)
25 }()
26 var gotSignal os.Signal
27 var wg sync.WaitGroup
28 wg.Go(func() {
29 select {
30 case gotSignal = <-c:
31 cancel()
32 case <-ctx.Done():
33 }
34 })
35
36 err := cmd.NewCmdRoot().ExecuteContext(ctx)
37 cancel()
38 wg.Wait()
39 if gotSignal != nil && err != nil {
40 err = fmt.Errorf("received %v signal from OS: %w", gotSignal.String(), err)
41 } else if gotSignal != nil {
42 err = fmt.Errorf("received %v signal from OS", gotSignal.String())
43 }
44 return err
45}
46
47func main() {
48 exitCode := 0

Callers 1

mainFunction · 0.85

Calls 2

ErrorfMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected