Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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', () => {
'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
}
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
}
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`)
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, [])
}
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, [])
}
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
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)