Skip to content

Commit

Permalink
chore: minor improvements to zenstack repl
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 committed Nov 8, 2023
1 parent eb6ef1f commit 379afbb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/schema/src/cli/actions/repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { inspect } from 'util';
/**
* CLI action for starting a REPL session
*/
export async function repl(projectPath: string, options: { prismaClient?: string }) {
export async function repl(projectPath: string, options: { prismaClient?: string; debug?: boolean; table?: boolean }) {
console.log('Welcome to ZenStack REPL. See help with the ".help" command.');
console.log('Global variables:');
console.log(` ${colors.cyan('db')} to access enhanced PrismaClient`);
Expand All @@ -19,14 +19,14 @@ export async function repl(projectPath: string, options: { prismaClient?: string
console.log(` ${colors.magenta('.auth { id: ... }')} - set current user`);
console.log(` ${colors.magenta('.table')} - toggle table output`);
console.log();
console.log(`Running as anonymous user. Use ${colors.magenta('.auth')} to set current user.`);
console.log(`Running as anonymous user. Use ".auth" to set current user.`);

const prismaClientModule = options.prismaClient ?? path.join(projectPath, './node_modules/.prisma/client');
const { PrismaClient } = require(prismaClientModule);
const { enhance } = require('@zenstackhq/runtime');

let debug = false;
let table = false;
let debug = !!options.debug;
let table = !!options.table;
let prisma: any;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
let db: any;
Expand Down Expand Up @@ -124,7 +124,6 @@ export async function repl(projectPath: string, options: { prismaClient?: string
} else {
// set current user
const user = eval(`(${value})`);
console.log(user);
if (!user || typeof user !== 'object') {
console.error(`Invalid argument. Pass a user object like { id: ... }`);
this.displayPrompt();
Expand Down
2 changes: 2 additions & 0 deletions packages/schema/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ export function createProgram() {
.command('repl')
.description('Start a REPL session.')
.option('--prisma-client <module>', 'path to Prisma client module')
.option('--debug', 'enable debug output')
.option('--table', 'enable table format output')
.action(replAction);

// make sure config is loaded before actions run
Expand Down

0 comments on commit 379afbb

Please sign in to comment.