unjs / unjs/citty

Support `setup` to return data

Open
#92 1 comment 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1.3k
Forks
58
PR merge metrics
No merged PRs in 30d

Description

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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No file or test is named. Start by tracing the defineCommand lifecycle from setup into run and inspect how arguments are passed to subcommands. Done should mean setup can return context-dependent data and run receives that data, with tests covering the new behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.