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.
This commit is contained in:
bobo.yang 2023-06-09 08:56:42 +08:00
parent 3d4ea2be70
commit d998dbd71d
3 changed files with 17 additions and 1 deletions

View File

@ -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);

View File

@ -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\""]
}

View File

@ -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"]
}