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 transformCommandToApi util #94

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

Support transformCommandToApi util #94

peterroe opened this issue Oct 18, 2023 · 1 comment

Comments

@peterroe
Copy link
Contributor

peterroe commented Oct 18, 2023

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

  • Would you be willing to help implement this feature?
@peterroe peterroe changed the title Support transformCommandToApi unil Support transformCommandToApi util Oct 18, 2023
@peterroe
Copy link
Contributor Author

peterroe commented Oct 19, 2023

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

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