func (c *ContextBuilder) initWg() *sync.WaitGroup { wg := wgctx.FromContextOrNil(c.ctx) if wg != nil { return wg } c.ctx = wgctx.NewContext(c.ctx) return wgctx.FromContext(c.ctx) }
func Initialise(ctx context.Context, overrides OptionsInterface) (context.Context, context.CancelFunc, error) { if overrides == nil { overrides = Flags{} } options := overrides.getOptions() ctx, cancel := context.WithCancel(ctx) ctx = jsonctx.AutoContext(ctx) ctx = wgctx.NewContext(ctx) ctx = sysctx.NewContext(ctx) cmd := &cmdctx.Cmd{} vos := vosctx.FromContext(ctx) path := "" cmd.Edit = options.Edit cmd.Validate = options.Validate cmd.Update = options.Update cmd.Log = options.Log cmd.Debug = options.Debug cmd.Port = options.Port if options.Path == "" { dir, err := vos.Getwd() if err != nil { return nil, nil, kerr.Wrap("OKOLXAMBSJ", err) } p, err := packages.GetPackageFromDir(ctx, dir) if err != nil { return nil, nil, kerr.Wrap("ADNJKTLAWY", err) } path = p } else { path = options.Path } ctx = cmdctx.NewContext(ctx, cmd) pcache, err := parser.Parse(ctx, path) if err != nil { return nil, nil, kerr.Wrap("EBMBIBIKUF", err) } ctx = envctx.NewContext(ctx, pcache.Env) return ctx, cancel, nil }