MCPcopy Create free account
hub / github.com/brimdata/super / InitWithSignals

Method InitWithSignals

cli/cli.go:44–74  ·  view source on GitHub ↗

InitWithSignals handles the flags defined in SetFlags, calls the Init method for each element of all, and returns a context canceled when any signal in signals is raised.

(all []Initializer, signals ...os.Signal)

Source from the content-addressed store, hash-verified

42// for each element of all, and returns a context canceled when any signal in
43// signals is raised.
44func (f *Flags) InitWithSignals(all []Initializer, signals ...os.Signal) (context.Context, context.CancelFunc, error) {
45 if f.showVersion {
46 fmt.Printf("Version: %s\n", Version())
47 os.Exit(0)
48 }
49 var err error
50 for _, flags := range all {
51 if initErr := flags.Init(); err == nil {
52 err = initErr
53 }
54 }
55 if err != nil {
56 return nil, nil, err
57 }
58 if f.cpuprofile != "" {
59 f.runCPUProfile(f.cpuprofile)
60 }
61 if f.trace != "" {
62 f.traceFile, err = os.Create(f.trace)
63 if err != nil {
64 log.Fatal(err)
65 }
66 trace.Start(f.traceFile)
67 }
68 ctx, cancel := signalContext(context.Background(), signals...)
69 cleanup := func() {
70 cancel()
71 f.cleanup()
72 }
73 return ctx, cleanup, nil
74}
75
76func signalContext(ctx context.Context, signals ...os.Signal) (context.Context, context.CancelFunc) {
77 ctx, cancel := context.WithCancelCause(ctx)

Callers 2

InitMethod · 0.95
RunMethod · 0.80

Calls 6

runCPUProfileMethod · 0.95
cleanupMethod · 0.95
VersionFunction · 0.85
signalContextFunction · 0.85
InitMethod · 0.65
StartMethod · 0.45

Tested by

no test coverage detected