How to use the @prisma/cli.arg function in @prisma/cli

To help you get started, weโ€™ve selected a few @prisma/cli examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github prisma / prisma2 / cli / introspection / src / bin.ts View on Github external
async function main(): Promise {
  process.env.NODE_ENV = 'production'
  // create a new CLI with our subcommands
  const args = arg(process.argv.slice(2), {})

  if (isError(args)) {
    console.error(args.message)
    return 1
  }

  const commands = {
    init: Init.new(),
    introspect: Introspect.new(),
  }

  if (commands[args._[0]]) {
    const result = await commands[args._[0]].parse(process.argv.slice(3))
    console.log(result)
  } else {
    console.error(`Command not found: ${args._[0]}. Available commands: ${Object.keys(commands).join(', ')}`)
github prisma / prisma2 / cli / prisma2 / src / CLI.ts View on Github external
async parse(argv: string[]): Promise {
    // parse the args according to the following spec
    const args = arg(argv, {
      '--help': Boolean,
      '-h': '--help',
      '--version': Boolean,
      '-v': '--version',
    })
    if (isError(args)) {
      return this.help(args.message)
    }
    if (args['--version']) {
      return Version.new().parse(argv)
    }
    // display help for help flag or no subcommand
    if (args._.length === 0 || args['--help']) {
      return this.help()
    }
github prisma / prisma2 / cli / introspection / src / commands / Init.ts View on Github external
async parse(argv: string[]): Promise {
    // parse the arguments according to the spec
    const args = arg(argv, {})

    if (isError(args)) {
      return null
    }

    if (args['--help']) {
      return this.help()
    }

    const outputDirName = args._[0]
    const outputDir = outputDirName ? path.join(process.cwd(), outputDirName) : process.cwd()

    if (fs.existsSync(outputDir)) {
      const schemaExists = fs.existsSync(path.join(outputDir, 'schema.prisma'))
      const prismaSchemaExists = fs.existsSync(path.join(outputDir, 'prisma/schema.prisma'))
      if (schemaExists || prismaSchemaExists) {
github prisma / lift / src / cli / commands / LiftUp.ts View on Github external
public async parse(argv: string[]): Promise {
    // parse the arguments according to the spec
    const args = arg(argv, {
      '--help': Boolean,
      '-h': '--help',
      '--preview': Boolean,
      '-p': '--preview',
      '--verbose': Boolean,
      '-v': '--verbose',
      '--create-db': Boolean,
      '-c': '--create-db',
      '--auto-approve': Boolean,
    })

    if (isError(args)) {
      return this.help(args.message)
    } else if (args['--help']) {
      return this.help()
    }
github prisma / lift / src / cli / commands / Converter.ts View on Github external
public async parse(argv: string[]): Promise {
    // parse the arguments according to the spec
    const args = arg(argv, {
      '--help': Boolean,
      '-h': '--help',
    })

    if (isError(args)) {
      return this.help(args.message)
    } else if (args['--help']) {
      return this.help()
    }

    const datamodel = await this.readStdin()
    const engine = new LiftEngine({ projectDir: process.cwd() })
    const parser = DefaultParser.create(DatabaseType.postgres)
    const isdl = parser.parseFromSchemaString(datamodel)
    return isdlToDatamodel2(isdl, [])
  }
github prisma / lift / src / cli / commands / LiftSave.ts View on Github external
public async parse(argv: string[]): Promise {
    // parse the arguments according to the spec
    const args = arg(argv, {
      '--help': Boolean,
      '-h': '--help',
      '--name': String,
      '-n': '--name',
      '--preview': Boolean,
      '-p': '--preview',
      '--create-db': Boolean,
      '-c': '--create-db',
    })
    if (isError(args)) {
      return this.help(args.message)
    } else if (args['--help']) {
      return this.help()
    }
    const preview = args['--preview'] || false
    await ensureDatabaseExists('create', true, args['--create-db'])
github prisma / lift / src / cli / commands / LiftCommand.ts View on Github external
public async parse(argv: string[]): Promise {
    // parse the arguments according to the spec
    const args = arg(argv, {
      '--help': Boolean,
      '-h': '--help',
    })
    if (isError(args)) {
      return this.help(args.message)
    }
    // display help for help flag or no subcommand
    if (args._.length === 0 || args['--help']) {
      return this.help()
    }
    // check if we have that subcommand
    const cmd = this.cmds[args._[0]]
    if (cmd) {
      const nextFreePort = await getNextFreePort(process.cwd())
      if (typeof nextFreePort !== 'number') {
        const command = `prisma2 lift ${argv.join(' ')}`
github prisma / prisma2 / cli / introspection / src / commands / Introspect.ts View on Github external
public async parse(argv: string[], minimalOutput = false): Promise {
    const args = arg(argv, {
      '--help': Boolean,
      '-h': '--help',
      '--url': String,
      '--print': Boolean,
    })

    const log = (...messages) => {
      if (!args['--print']) {
        console.log(...messages)
      }
    }

    if (args instanceof Error) {
      return this.help(args.message)
    }
github prisma / lift / src / cli / commands / LiftWatch.ts View on Github external
public async parse(argv: string[]): Promise {
    const args = arg(argv, {
      '--preview': Boolean,
      '-p': '--preview',
      '--create-db': Boolean,
      '-c': '--create-db',
      '--auto-approve': Boolean,
    })
    const preview = args['--preview'] || false

    await occupyPath(process.cwd())

    await ensureDatabaseExists('dev', false, args['--create-db'] || process.platform === 'win32')

    const lift = new Lift()
    return lift.watch({
      preview,
      providerAliases: this.providerAliases,

@prisma/cli

Prisma is an open-source database toolkit. It includes a JavaScript/TypeScript ORM for Node.js, migrations and a modern GUI to view and edit the data in your database. You can use Prisma in new projects or add it to an existing one.

Apache-2.0
Latest version published 4 years ago

Package Health Score

65 / 100
Full package analysis