From d998dbd71da937dad6d076843758119be080b7e3 Mon Sep 17 00:00:00 2001 From: "bobo.yang" Date: Fri, 9 Jun 2023 08:56:42 +0800 Subject: [PATCH] Add edit functionality to custom contexts - Add edit property to CustomContext interface. - Implement edit functionality in CustomContexts class. - Update _setting_.json files for git_log_for_releasenote and tree contexts. --- src/context/customContext.ts | 14 ++++++++++++++ .../context/git_log_for_releasenote/_setting_.json | 1 + workflows/tree/context/tree/_setting_.json | 3 ++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/context/customContext.ts b/src/context/customContext.ts index b659b24..220f84e 100644 --- a/src/context/customContext.ts +++ b/src/context/customContext.ts @@ -3,12 +3,14 @@ import path from 'path'; import { logger } from '../util/logger'; import { runCommandStringArrayAndWriteOutput, runCommandStringAndWriteOutputSync, CommandResult } from '../util/commonUtil'; +import { UiUtilWrapper } from '../util/uiUtil'; export interface CustomContext { name: string; description: string; command: string[]; + edit: boolean | undefined; path: string; } @@ -49,6 +51,7 @@ class CustomContexts { name: settings.name, description: settings.description, command: settings.command, + edit: settings.edit, path: path.join(contextDirPath, contextDir) }; this.contexts.push(context); @@ -86,6 +89,17 @@ class CustomContexts { }); if (commandArray.length === 1) { + if (context.edit === true) { + // prompt input box for user to edit the commandArray[0] + const newCommand: string | undefined = await UiUtilWrapper.showInputBox({ + placeHolder: 'Edit the command', + value: commandArray[0] + }); + if (!newCommand) { + return { exitCode: 1, stdout: '', stderr: 'Command is empty' }; + } + return runCommandStringAndWriteOutputSync(newCommand!, outputFile); + } return runCommandStringAndWriteOutputSync(commandArray[0], outputFile); } return await runCommandStringArrayAndWriteOutput(commandArray, outputFile); diff --git a/workflows/default/context/git_log_for_releasenote/_setting_.json b/workflows/default/context/git_log_for_releasenote/_setting_.json index 30211f0..ffe6b46 100644 --- a/workflows/default/context/git_log_for_releasenote/_setting_.json +++ b/workflows/default/context/git_log_for_releasenote/_setting_.json @@ -1,5 +1,6 @@ { "name": "git_log_releasenote", "description": "git log for write release note", + "edit": true, "command": ["git log $(git describe --tags --abbrev=0)..HEAD --pretty=format:\"%h - %B\""] } \ No newline at end of file diff --git a/workflows/tree/context/tree/_setting_.json b/workflows/tree/context/tree/_setting_.json index 187551a..73c6fa3 100644 --- a/workflows/tree/context/tree/_setting_.json +++ b/workflows/tree/context/tree/_setting_.json @@ -1,5 +1,6 @@ { "name": "tree", "description": "Directory structure of workspace", - "command": ["tree", "-I", "__pycache__|\\.pytest_cache"] + "edit": true, + "command": ["tree -I __pycache__|\\.pytest_cache"] } \ No newline at end of file