feat: add debug mode to client

This commit is contained in:
wancat committed 2023-08-30 19:52:02 +08:00
1 parent e16b328892
commit d9836318db
1 file changed
+8 -2
+8 -2
View File
@@ -14,6 +14,12 @@ stdin.setRawMode(true)
stdin.resume() stdin.resume()
stdin.setEncoding('utf8') stdin.setEncoding('utf8')
function debug(...args) {
if (program.opts().debug) {
console.debug(...args)
}
}
async function createdSession() { async function createdSession() {
console.log('Creating a new session...') console.log('Creating a new session...')
const res = await fetch(`${program.opts().host}/api/v1/sessions`, { const res = await fetch(`${program.opts().host}/api/v1/sessions`, {
@@ -73,8 +79,7 @@ async function connect(sessionId) {
}) })
socket.on('graph', (data) => { socket.on('graph', (data) => {
console.log('receive graph:') debug('receive graph:', data)
console.log(data)
}) })
socket.on('close', function close() { socket.on('close', function close() {
@@ -107,6 +112,7 @@ async function main() {
program program
.option('-s, --session <string>', 'Session ID') .option('-s, --session <string>', 'Session ID')
.option('-c, --create', 'Create a new session') .option('-c, --create', 'Create a new session')
.option('-d, --debug', 'Debug mode')
.option( .option(
'-h, --host <string>', '-h, --host <string>',
'Server host', 'Server host',