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

feat: Add commander task for CLI option parsing #48

Merged
merged 1 commit into from
Jan 4, 2024
Merged

Conversation

daffl
Copy link
Member

@daffl daffl commented Jan 4, 2024

This pull request streamlines command line option parsing. Instead of exporting a separate command, we are now passing the generator command line options as ctx.argv which makes it much more flexible. Also adds a commander task that allows to use commander programs to parse the arguments:

import { PinionContext, commander, Command, generator } from '../../src/index.js'

interface Context extends PinionContext {
  name: string
}

const program = new Command()
  .description('A test command')
  .option('-n, --name <name>', 'Name of your project')

export const generate = (ctx: Context) =>
  generator(ctx)
    .then(commander(program))
    .then(ctx => {
      console.log(ctx.name)
    })

Copy link

@marshallswain marshallswain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@daffl daffl merged commit cf3fc7a into main Jan 4, 2024
4 checks passed
@daffl daffl deleted the commander-task branch January 4, 2024 18:46
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

Successfully merging this pull request may close these issues.

2 participants