Skip to content

Commit

Permalink
Merge pull request #720 from mbektas/support-remote-urls-with-cli
Browse files Browse the repository at this point in the history
support setting remote jupyterlab URLs via CLI
  • Loading branch information
mbektas authored Oct 26, 2023
2 parents dcd2440 + 1f10fde commit 453ad3f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/main/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
17 changes: 17 additions & 0 deletions src/main/config/sessionconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
5 changes: 0 additions & 5 deletions src/main/sessionwindow/sessionwindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
1 change: 1 addition & 0 deletions src/main/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export interface ICLIArguments {
[x: string]: unknown;
pythonPath: string | unknown;
workingDir: string | unknown;
persistSessionData: boolean | unknown;
}

export interface IRect {
Expand Down

0 comments on commit 453ad3f

Please sign in to comment.