Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cmd.Use(fn).Run(fn) #5

Open
matthewmueller opened this issue Jan 12, 2025 · 0 comments
Open

Support cmd.Use(fn).Run(fn) #5

matthewmueller opened this issue Jan 12, 2025 · 0 comments

Comments

@matthewmueller
Copy link
Contributor

matthewmueller commented Jan 12, 2025

When you have to configure global dependencies like the logger, you currently need to wrap the runners

func wrap(fn func(ctx context.Context) error) func(ctx context.Context) error {
	return func(ctx context.Context) error {
		return fn(ctx)
	}
}

// usage

cmd.Run(wrap(func(ctx context.Context) error {
	return c.Download(ctx, in)
}))

This isn't bad, but it'd be nice to able to just call cmd.Use(...).Run(...) to configure "middleware". Ideally you could do it higher up, so you don't need to do it for every command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant