From 1f10fdeea4d99264c15398db46e8c90ebec0a63a Mon Sep 17 00:00:00 2001 From: Mehmet Bektas Date: Wed, 25 Oct 2023 20:19:11 -0700 Subject: [PATCH] support setting remote jupyterlab URLs via CLI --- src/main/cli.ts | 5 +++++ src/main/config/sessionconfig.ts | 17 +++++++++++++++++ src/main/sessionwindow/sessionwindow.ts | 5 ----- src/main/tokens.ts | 1 + 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/main/cli.ts b/src/main/cli.ts index 08423c6a..6b04b259 100644 --- a/src/main/cli.ts +++ b/src/main/cli.ts @@ -54,6 +54,11 @@ export function parseCLIArgs(argv: string[]) { describe: 'Python path', type: 'string' }) + .option('persist-session-data', { + describe: 'Persist session data for remote server connections', + type: 'boolean', + default: true + }) .option('working-dir', { describe: 'Working directory', type: 'string' diff --git a/src/main/config/sessionconfig.ts b/src/main/config/sessionconfig.ts index 4664977f..5dbcf572 100644 --- a/src/main/config/sessionconfig.ts +++ b/src/main/config/sessionconfig.ts @@ -89,6 +89,11 @@ export class SessionConfig { ): SessionConfig { const sessionConfig = new SessionConfig(); sessionConfig.remoteURL = remoteURL; + const url = new URL(remoteURL); + const token = url.searchParams.get('token'); + sessionConfig.url = url; + sessionConfig.token = token; + sessionConfig.persistSessionData = persistSessionData !== false; if (partition) { sessionConfig.partition = partition; @@ -109,6 +114,18 @@ export class SessionConfig { let pythonPath = ''; try { + for (const arg of cliArgs._) { + const strArg = arg.toString(); + if (/^https?:\/\//.test(strArg)) { + const remoteURL = strArg; + return SessionConfig.createRemote( + remoteURL, + cliArgs.persistSessionData === true, + undefined + ); + } + } + let skipFilePaths = false; if (workingDir) { workingDir = path.resolve(workingDir as string); diff --git a/src/main/sessionwindow/sessionwindow.ts b/src/main/sessionwindow/sessionwindow.ts index dc050dbc..1341684f 100644 --- a/src/main/sessionwindow/sessionwindow.ts +++ b/src/main/sessionwindow/sessionwindow.ts @@ -1359,17 +1359,12 @@ export class SessionWindow implements IDisposable { this._showProgressView('Connecting to JupyterLab Server'); try { - const url = new URL(remoteURL); - const token = url.searchParams.get('token'); - this._sessionConfig = SessionConfig.createRemote( remoteURL, persistSessionData, partition ); const sessionConfig = this._sessionConfig; - sessionConfig.url = url; - sessionConfig.token = token; appData.addRemoteURLToRecents(remoteURL); appData.addSessionToRecents({ diff --git a/src/main/tokens.ts b/src/main/tokens.ts index b492eb96..7bc37bd0 100644 --- a/src/main/tokens.ts +++ b/src/main/tokens.ts @@ -87,6 +87,7 @@ export interface ICLIArguments { [x: string]: unknown; pythonPath: string | unknown; workingDir: string | unknown; + persistSessionData: boolean | unknown; } export interface IRect {