Repository: MotiaDev/motia
File: packages/snap/src/cli.ts (TypeScript)

Code before:
  compilerOptions: { module: 'commonjs' },
})

program
  .command('version')
  .description('Display detailed version information')
  .action(() => {
    console.log(`Motia CLI v${version}`)
    process.exit(0)
  })

program
  .command('create')
  .description('Create a new motia project')
  .argument('[folder]', 'The name for your project (optional)')
  .option('-t, --template <template>', 'The template to use for your project')
  .option('-i, --interactive', 'Use interactive prompts to create project') // it's default
  .option('-c, --confirm', 'Confirm the project creation', false)
  .action(
    handler(async (arg, context) => {
      const { createInteractive } = require('./create/interactive')
      const inquirer = require('inquirer')
      let folder = arg.folder
      if (!folder) {
        const { projectName } = await inquirer.prompt([
          {
            type: 'input',
            name: 'projectName',
            message: 'Enter project folder name:',
            default: 'my-motia-app',
          },
        ])
        folder = projectName
      }
      await createInteractive(
        {
          name: folder,
          template: arg.template,
          confirm: !!arg.confirm,
        },
        context,
      )
    }),
  )

program
  .command('rules')
  .command('pull')
  .description('Install essential AI development guides (AGENTS.md, CLAUDE.md) and optional Cursor IDE rules')
  .option('-f, --force', 'Overwrite existing files')
  .action(

Review comment (suggestion):
I believe this wont work, in commander the first parameter will always be the argument. 

In this case if someone runs `pnpm motia create my-project --template base`

Then `arg` will have the value "my-project", hence `arg.confirm` or `arg.template` will result into `undefined`

Reference: https://github.com/tj/commander.js/blob/master/examples/thank.js


Code after:
  compilerOptions: { module: 'commonjs' },
})

program
  .command('version')
  .description('Display detailed version information')
  .action(() => {
    console.log(`Motia CLI v${version}`)
    process.exit(0)
  })

program
  .command('create [project name]')
  .description('Create a new motia project')
  .option('-t, --template <template>', 'The template to use for your project')
  .option('-i, --interactive', 'Use interactive prompts to create project') // it's default
  .option('-c, --confirm', 'Confirm the project creation', false)
  .action((projectName, options) => {
    const mergedArgs = { ...options, name: projectName };
    return handler(async (arg, context) => {
      const { createInteractive } = require('./create/interactive');
      await createInteractive(
        {
          name: arg.name,
          template: arg.template,
          confirm: !!arg.confirm,
        },
        context
      );
    })(mergedArgs);
  });

program
  .command('rules')
  .command('pull')
  .description('Install essential AI development guides (AGENTS.md, CLAUDE.md) and optional Cursor IDE rules')
  .option('-f, --force', 'Overwrite existing files')
  .action(
    handler(async (arg, context) => {
      const { pullRules } = require('./create/pull-rules')
      await pullRules({ force: arg.force, rootDir: process.cwd() }, context)
    }),
  )

program
  .command('generate-types')
  .description('Generate types.d.ts file for your project')
  .action(async () => {
    const { generateTypes } = require('./generate-types')
    await generateTypes(process.cwd())
    process.exit(0)