How to use the @prisma/cli.isError 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 / lift / src / bin.ts View on Github external
async function main(): Promise {
  // create a new CLI with our subcommands
  const cli = LiftCommand.new({
    save: LiftSave.new(),
    up: LiftUp.new(),
    down: LiftDown.new(),
    dev: LiftWatch.new(providerAliases),
    ['tmp-prepare']: LiftTmpPrepare.new(),
    studio: StudioCommand.new(providerAliases),
  })
  // parse the arguments
  const result = await cli.parse(process.argv.slice(2))
  if (result instanceof HelpError) {
    console.error(result)
    return 1
  } else if (isError(result)) {
    console.error(result)
    return 1
  }
  console.log(result)

  return 0
}
process.on('SIGINT', () => {
github prisma / prisma2 / cli / prisma2 / src / bin.ts View on Github external
'tmp-prepare': LiftTmpPrepare.new(),
      introspect: Introspect.new(),
      dev: LiftWatch.new(aliases),
      studio: StudioCommand.new(aliases),
      generate: Generate.new(),
      version: Version.new(),
      validate: Validate.new(),
    },
    ['init', 'lift', 'tmp-prepare', 'introspect', 'dev', 'studio', 'generate', 'validate'],
  )
  // parse the arguments
  const result = await cli.parse(process.argv.slice(2))
  if (result instanceof HelpError) {
    console.error(result.message)
    return 1
  } else if (isError(result)) {
    console.error(result)
    return 1
  }
  console.log(result)

  return 0
}
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(', ')}`)
    return 1
  }
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(' ')}`
        throw new Error(`Cannot run ${chalk.bold(command)} because there is a ${chalk.bold(
          'prisma2 dev',
        )} command running in this directory.
Please ${gamboge(`stop ${chalk.bold('prisma2 dev')} first`)}, then try ${chalk.greenBright.bold(command)} again`)
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 / photonjs / packages / photon / src / 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 parser = DefaultParser.create(DatabaseType.postgres)
    const isdl = parser.parseFromSchemaString(datamodel)
    return isdlToDatamodel2(isdl, [])
  }
github prisma / lift / src / cli / commands / LiftDown.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',
    })

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

    const lift = new Lift()

    const options: DownOptions = {
      n: args._.pop(),
    }

    await ensureDatabaseExists('unapply', true)

    const result = await lift.down(options)
    lift.stop()
    return result
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()
    }

    const lift = new Lift()

    const options: UpOptions = {
      preview: args['--preview'],
      verbose: args['--verbose'],
      autoApprove: args['--auto-approve'],
    }

    if (args._.length > 0) {
      const thisArg = args._[0]
      const maybeNumber = parseInt(thisArg, 10)

@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