From b0a9d37d75e4eea8f70ce637b4ac3ea546b9de0e Mon Sep 17 00:00:00 2001 From: Lau <5364453+lask@users.noreply.github.com> Date: Fri, 24 Sep 2021 11:18:40 +0200 Subject: [PATCH] Change org to project (#150) --- vscode/src/extension.ts | 4 +- vscode/src/{org.ts => project.ts} | 14 +++---- vscode/src/{organization.ts => projectCmd.ts} | 18 ++++----- vscode/src/utils.ts | 38 +++++++++---------- 4 files changed, 37 insertions(+), 37 deletions(-) rename vscode/src/{org.ts => project.ts} (57%) rename vscode/src/{organization.ts => projectCmd.ts} (65%) diff --git a/vscode/src/extension.ts b/vscode/src/extension.ts index 53fb382..f7de498 100644 --- a/vscode/src/extension.ts +++ b/vscode/src/extension.ts @@ -6,8 +6,8 @@ import { clean, gt } from "semver"; import { commands as Commands, env, ExtensionContext, Uri, window as Window } from "vscode"; import { activateTreeView, deactivateTreeView } from "./deviceView"; import { activateLsp, deactivateLsp } from "./lspClient"; -import { activateToitStatusBar, createSetOrgCommand } from "./organization"; import { createOutputCommand } from "./output"; +import { activateToitStatusBar, createSetProjectCommand } from "./projectCmd"; import { activateSerialView } from "./serialView"; import { createEnsureAuth } from "./toitAuth"; import { createDeployCommand, createRunCommand } from "./toitExec"; @@ -72,7 +72,7 @@ export async function activate(extContext: ExtensionContext): Promise { extContext.subscriptions.push(Commands.registerCommand("toit.devRun", createRunCommand(ctx))); extContext.subscriptions.push(Commands.registerCommand("toit.devDeploy", createDeployCommand(ctx))); extContext.subscriptions.push(Commands.registerCommand("toit.devLogs", createOutputCommand(ctx))); - extContext.subscriptions.push(Commands.registerCommand("toit.setOrganization", createSetOrgCommand(ctx))); + extContext.subscriptions.push(Commands.registerCommand("toit.setProject", createSetProjectCommand(ctx))); extContext.subscriptions.push(Commands.registerCommand("toit.stopSimulator", createStopSimCommand(ctx))); extContext.subscriptions.push(Commands.registerCommand("toit.startSimulator", createStartSimCommand(ctx))); extContext.subscriptions.push(Commands.registerCommand("toit.revealDevice", async(hwID) => await revealDevice(ctx, hwID))); diff --git a/vscode/src/org.ts b/vscode/src/project.ts similarity index 57% rename from vscode/src/org.ts rename to vscode/src/project.ts index 7e85bbe..597ba84 100644 --- a/vscode/src/org.ts +++ b/vscode/src/project.ts @@ -4,18 +4,18 @@ // Use of this source code is governed by an MIT-style license that can be // found in the LICENSE file. -export interface ConsoleOrganization { +export interface ConsoleProject { name: string; - organization_id: string; + project_id: string; } /* eslint-enable @typescript-eslint/naming-convention */ -export class Organization { +export class Project { name: string; - organizationID: string; + projectID: string; - constructor(org: ConsoleOrganization) { - this.name = org.name; - this.organizationID = org.organization_id; + constructor(project: ConsoleProject) { + this.name = project.name; + this.projectID = project.project_id; } } diff --git a/vscode/src/organization.ts b/vscode/src/projectCmd.ts similarity index 65% rename from vscode/src/organization.ts rename to vscode/src/projectCmd.ts index c9da561..b8092fc 100644 --- a/vscode/src/organization.ts +++ b/vscode/src/projectCmd.ts @@ -3,14 +3,14 @@ // found in the LICENSE file. import { ExtensionContext, StatusBarAlignment, window as Window } from "vscode"; -import { Context, ensureAuth, getFirmwareVersion, getOrganization, isAuthenticated, selectOrganization, setOrganization } from "./utils"; +import { Context, ensureAuth, getFirmwareVersion, getProject, isAuthenticated, selectProject, setProject } from "./utils"; export async function activateToitStatusBar(ctx: Context, extensionContext: ExtensionContext): Promise { const toitStatus = Window.createStatusBarItem(StatusBarAlignment.Left, 100); extensionContext.subscriptions.push(toitStatus); ctx.setStatusBar(toitStatus); updateStatus(ctx); - toitStatus.command = "toit.setOrganization"; + toitStatus.command = "toit.setProject"; toitStatus.show(); } @@ -18,26 +18,26 @@ export async function updateStatus(ctx: Context): Promise { if (!await isAuthenticated(ctx)) return; const toitStatus = ctx.getStatusBar(); if (!toitStatus) return; - const org = await getOrganization(ctx); + const project = await getProject(ctx); const firmwareVersion = await getFirmwareVersion(ctx); - toitStatus.text = `Toit: ${org} (${firmwareVersion})`; + toitStatus.text = `Toit: ${project} (${firmwareVersion})`; } async function executeCommand(ctx: Context) { if (!await ensureAuth(ctx)) return; - const org = await selectOrganization(ctx); - if (org === undefined) return; + const project = await selectProject(ctx); + if (project === undefined) return; try { - await setOrganization(ctx, org); + await setProject(ctx, project); await updateStatus(ctx); ctx.views.refreshViews(); } catch (e) { - return Window.showErrorMessage(`Unable to change organization: ${e.message}.`); + return Window.showErrorMessage(`Unable to change project: ${e.message}.`); } } -export function createSetOrgCommand(ctx: Context): () => void { +export function createSetProjectCommand(ctx: Context): () => void { return async() => executeCommand(ctx); } diff --git a/vscode/src/utils.ts b/vscode/src/utils.ts index 13971e0..d154e7b 100644 --- a/vscode/src/utils.ts +++ b/vscode/src/utils.ts @@ -6,9 +6,9 @@ import { InputBoxOptions, QuickPickItem, StatusBarItem, window as Window, worksp import { App, ConsoleApp } from "./app"; import { toitExecFilePromise } from "./cli"; import { ConsoleDevice, ConsoleDeviceInfo, Device, DeviceInfo, RelatedDevice } from "./device"; -import { ConsoleOrganization, Organization } from "./org"; -import { updateStatus } from "./organization"; import { Output } from "./output"; +import { ConsoleProject as ConsoleProject, Project as Project } from "./project"; +import { updateStatus } from "./projectCmd"; import { ConsoleSerialInfo, SerialInfo, SerialPort, SerialStatus } from "./serialPort"; import { Views } from "./views"; @@ -138,8 +138,8 @@ interface AuthInfo { email?: string; id?: string; name?: string; - organization_id?: string; - organization_name?: string; + project_id?: string; + project_name?: string; status: string; /* eslint-enable @typescript-eslint/naming-convention */ } @@ -234,41 +234,41 @@ export async function uninstallApp(ctx: Context, app: App): Promise { await toitExecFilePromise(ctx, "dev", "-d", app.deviceID, "uninstall", app.jobID ); } -class OrganizationItem extends Organization implements QuickPickItem { +class ProjectItem extends Project implements QuickPickItem { label: string; - constructor(org: ConsoleOrganization) { - super(org); + constructor(project: ConsoleProject) { + super(project); this.label = this.name; } } -export async function getOrganization(ctx: Context): Promise { +export async function getProject(ctx: Context): Promise { if (!await isAuthenticated(ctx)) return undefined; const { stdout } = await toitExecFilePromise(ctx, "project", "get" ); // The output of the command if of the form: // Logged in to Toitware // 01234567890123 - const orgStrOffset = 13; - return stdout.slice(orgStrOffset).trimEnd(); + const projectStrOffset = 13; + return stdout.slice(projectStrOffset).trimEnd(); } -async function listOrganizations(ctx: Context): Promise { +async function listProjects(ctx: Context): Promise { const { stdout } = await toitExecFilePromise(ctx, "project", "list", "-o", "json"); return stdout.split("\n"). filter(str => str !== ""). - map(json => JSON.parse(json) as ConsoleOrganization). - map(org => new OrganizationItem(org)); + map(json => JSON.parse(json) as ConsoleProject). + map(project => new ProjectItem(project)); } -export async function selectOrganization(ctx: Context): Promise { - const organizations = await listOrganizations(ctx); - return await Window.showQuickPick(organizations, { "placeHolder": "Pick an organization" }); +export async function selectProject(ctx: Context): Promise { + const projects = await listProjects(ctx); + return await Window.showQuickPick(projects, { "placeHolder": "Pick a project" }); } -export async function setOrganization(ctx: Context, org: Organization): Promise { - await toitExecFilePromise(ctx, "project", "use", org.organizationID); +export async function setProject(ctx: Context, project: Project): Promise { + await toitExecFilePromise(ctx, "project", "use", project.projectID); } export function getToitPath(): string { @@ -307,7 +307,7 @@ export async function revealDevice(ctx: Context, hwid: string): Promise { const device = await ctx.views.getDeviceProvider()?.getDevice(deviceInfo.deviceID); if (!device) { - return; // TODO(Lau): Add warning or error message? Make sure to differentiate between hidden view and wrong org. + return; // TODO(Lau): Add warning or error message? Make sure to differentiate between hidden view and wrong project. } await ctx.views.getDeviceView()?.reveal(device, { "focus": true, "select": false, "expand": true }); }