wrap wraps a function with middleware using a new context. It returns a cli.ActionFunc with the cli.Context added to the Context.
(fn func(context.Context) error, middleware ...func(context.Context) (context.Context, error))
| 38 | // wrap wraps a function with middleware using a new context. It returns a cli.ActionFunc with |
| 39 | // the cli.Context added to the Context. |
| 40 | func wrap(fn func(context.Context) error, middleware ...func(context.Context) (context.Context, error)) cli.ActionFunc { |
| 41 | return func(clictx *cli.Context) error { |
| 42 | ctx := context.Background() |
| 43 | |
| 44 | // apply middleware to the new context |
| 45 | for _, fn := range middleware { |
| 46 | var err error |
| 47 | if ctx, err = fn(ctx); err != nil { |
| 48 | return err |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | ctx = withCLIContext(ctx, clictx) |
| 53 | |
| 54 | return fn(ctx) |
| 55 | } |
| 56 | } |
no test coverage detected
searching dependent graphs…