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 setup to return data #92

Open
1 task done
peterroe opened this issue Oct 16, 2023 · 1 comment
Open
1 task done

Support setup to return data #92

peterroe opened this issue Oct 16, 2023 · 1 comment

Comments

@peterroe
Copy link
Contributor

Describe the feature

export default defineCommand({
    meta: {
        name: 'test',
        description: 'Test command',
    },
    async setup(context) {
        const data = someComputed(context)
		return { data }
    },
    async run({ args }, { data }) {
		console.log(data)
	}
})

Reason

The return value of setup could be useful, in addition to some initialization behavior, it could potentially produce different values depending on the context, which could be used in setup and passed to all subcommands in the run method arguments!

Of course, I may not have thought this through completely, does anyone else have a better suggestion?

Additional information

  • Would you be willing to help implement this feature?
@peterroe
Copy link
Contributor Author

Currently it can only be passed implicitly by putting the variable into global scope, or mounting it on a context object. I don't think this is a good and safe way to 👀

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