diff --git a/vscode-extensions/vscode-spring-cli/package.json b/vscode-extensions/vscode-spring-cli/package.json index 97ac8e2c0..c0bbce68d 100644 --- a/vscode-extensions/vscode-spring-cli/package.json +++ b/vscode-extensions/vscode-spring-cli/package.json @@ -71,6 +71,11 @@ "command": "vscode-spring-cli.project.remove", "title": "Remove Project", "category": "Spring CLI" + }, + { + "command": "vscode-spring-cli.command.add", + "title": "Add Command", + "category": "Spring CLI" } ], "configuration": { @@ -82,7 +87,27 @@ "description": "Spring CLI executable. Either name of the executable if it's on the PATH environment variable or absolute path to the spring CLI executable (or JAR for dev purposes)" } } - } + }, + "taskDefinitions": [ + { + "type": "spring-cli", + "required": ["command", "subcommand"], + "properties": { + "command": { + "type": "string", + "description": "The command to execute" + }, + "subcommand": { + "type": "string", + "description": "The sub-command to execute" + }, + "arguments": { + "type": "array", + "description": "The parameters of the command" + } + } + } + ] }, "main": "./out/extension", "scripts": { diff --git a/vscode-extensions/vscode-spring-cli/src/cli-types.ts b/vscode-extensions/vscode-spring-cli/src/cli-types.ts index b50f8f557..cc3594dca 100644 --- a/vscode-extensions/vscode-spring-cli/src/cli-types.ts +++ b/vscode-extensions/vscode-spring-cli/src/cli-types.ts @@ -20,6 +20,10 @@ export interface BootAddMetadata { catalog?: string; } +export interface commandAddMetadata { + url: string; +} + export interface ProjectCatalog { name: string; url: string; diff --git a/vscode-extensions/vscode-spring-cli/src/cli.ts b/vscode-extensions/vscode-spring-cli/src/cli.ts index 5dfc1bd0d..dfb373961 100644 --- a/vscode-extensions/vscode-spring-cli/src/cli.ts +++ b/vscode-extensions/vscode-spring-cli/src/cli.ts @@ -1,4 +1,4 @@ -import { BootAddMetadata, BootNewMetadata, Project, ProjectCatalog } from "./cli-types"; +import { BootAddMetadata, BootNewMetadata, Project, ProjectCatalog, commandAddMetadata } from "./cli-types"; import { ProcessExecution, ProgressLocation, Task, TaskScope, Uri, env, tasks, window, workspace } from "vscode"; import cp from "child_process"; import { homedir } from "os"; @@ -28,6 +28,16 @@ export class Cli { return this.fetchJson("Fetching Available Catalogs...", undefined, ["project-catalog", "list-available"]); } + commandAdd(metadata: commandAddMetadata) { + const args = [ + "command", + "add", + "--from", + metadata.url + ]; + this.exec("Add Command", metadata.url, args); + } + projectCatalogAdd(catalog: ProjectCatalog): Promise { const args = [ "project-catalog", @@ -135,7 +145,7 @@ export class Cli { return new Promise(async (resolve, reject) => { const processOpts = { cwd: cwd || getWorkspaceRoot()?.fsPath || homedir() }; const process = this.executable.endsWith(".jar") ? new ProcessExecution("java", [ "-jar", this.executable, ...args], processOpts) : new ProcessExecution(this.executable, args, processOpts); - const task = new Task({ type: SPRING_CLI_TASK_TYPE}, cwd ? workspace.getWorkspaceFolder(Uri.file(cwd)) : TaskScope.Global, `${title}: ${message}`, SPRING_CLI_TASK_TYPE, process); + const task = new Task({ type: SPRING_CLI_TASK_TYPE }, cwd ? workspace.getWorkspaceFolder(Uri.file(cwd)) : TaskScope.Global, `${title}: ${message}`, SPRING_CLI_TASK_TYPE, process); const taskExecution = await tasks.executeTask(task); if (cancellation.isCancellationRequested) { reject(); diff --git a/vscode-extensions/vscode-spring-cli/src/command.ts b/vscode-extensions/vscode-spring-cli/src/command.ts new file mode 100644 index 000000000..5146df340 --- /dev/null +++ b/vscode-extensions/vscode-spring-cli/src/command.ts @@ -0,0 +1,35 @@ +import { Uri, window } from "vscode"; +import { enterText } from "./utils"; +import { CLI } from "./extension"; + +export async function handleCommandAdd() { + let url; + try { + url = await enterText({ + title: "URL", + prompt: "Enter Repository URL", + placeholder: "https://github.com/my-org/my-command", + validate: async v => { + try { + Uri.parse(v, true); + } catch (error) { + return "Invalid URL value"; + } + } + }); + } catch (error) { + // Cancelled - ignore the error + } + + if (url) { + CLI.commandAdd({url}); + } +} + +export async function handleCommandRemove() { + window.showErrorMessage("Not Implemented!"); +} + +export async function handleCommandNew() { + window.showErrorMessage("Not Implemented!"); +} \ No newline at end of file