citty
citty copied to clipboard
Support `transformCommandToApi` util
Describe the feature
// build.ts
export default defineCommand({
meta: {
name: 'build',
description: 'build command',
},
args: {
minify: {
type: 'boolean',
description: 'minify file size',
},
mode: {
type: 'string',
description: 'environment variable'
}
}
})
// api/index.ts
import build from './build'
import { transformCommandToApi } from 'citty'
export const apiBuild = transformCommandToApi(build)
// test.ts
import { apiBuild } from './api'
apiBuild({ // directly invoke with api
minify: true,
mode: false
})
Reason
Because defineCommand already defines all the information related to a command, it is very easy to convert it into a direct call to API.
Additional information
- [X] Would you be willing to help implement this feature?
This function looks similar to the creadeMain function, but it will be much more convenient to use. If this idea is agreed, I will start a PR. 👀 @pi0