extract act options from cli command (#117)
* extract act options from cli command * remove special options handled by the tree view * Refactor logic to get act options (#1) * Refactor get options logic * Remove bool type options from having descriptions * Force option description to be uppercase Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com> * disable generic early exit options as well * filter out stringArray default value * this removes default values like `[]` regardless if they are sent * fix quote consitency --------- Signed-off-by: Sanjula Ganepola <sanjulagane@gmail.com> Co-authored-by: Sanjula Ganepola <32170854+SanjulaGanepola@users.noreply.github.com>
This commit is contained in:
27
src/act.ts
27
src/act.ts
@@ -120,6 +120,13 @@ export interface CommandArgs {
|
||||
extraHeader: { key: string, value: string }[]
|
||||
}
|
||||
|
||||
export interface ActOption {
|
||||
default: string;
|
||||
name: string,
|
||||
description: string
|
||||
type: string
|
||||
}
|
||||
|
||||
export class Act {
|
||||
static defaultActCommand: string = 'act';
|
||||
static githubCliActCommand: string = 'gh act';
|
||||
@@ -323,6 +330,26 @@ export class Act {
|
||||
}
|
||||
}
|
||||
|
||||
getAllOptions(): Promise<ActOption[]> {
|
||||
return new Promise<ActOption[]>((resolve, reject) => {
|
||||
const exec = childProcess.spawn(
|
||||
`${Act.getActCommand()} --list-options`,
|
||||
{
|
||||
shell: true,
|
||||
}
|
||||
);
|
||||
let options: string = ""
|
||||
exec.stdout.on('data', b => options += b.toString());
|
||||
exec.on('exit', async (code, signal) => {
|
||||
if (code === 0) {
|
||||
resolve(JSON.parse(options));
|
||||
} else {
|
||||
reject(new Error("Not supported by this binary"));
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
async runCommand(commandArgs: CommandArgs) {
|
||||
// Check if required components are ready
|
||||
// const unreadyComponents = await this.componentsManager.getUnreadyComponents();
|
||||
|
||||
@@ -117,7 +117,33 @@ export default class SettingsTreeDataProvider implements TreeDataProvider<Github
|
||||
}
|
||||
}),
|
||||
commands.registerCommand('githubLocalActions.addOption', async (optionsTreeItem: OptionsTreeItem) => {
|
||||
let options: any[] = [
|
||||
let options: any[];
|
||||
|
||||
try {
|
||||
const allOptions = await act.getAllOptions();
|
||||
const specialOptions: string[] = [
|
||||
Option.Input,
|
||||
Option.InputFile,
|
||||
Option.Var,
|
||||
Option.VarFile,
|
||||
Option.Secret,
|
||||
Option.SecretFile,
|
||||
Option.EventPath,
|
||||
Option.Platform,
|
||||
// The following options would break this integration
|
||||
Option.Help,
|
||||
Option.BugReport,
|
||||
Option.Watch,
|
||||
Option.List,
|
||||
Option.Version
|
||||
];
|
||||
options = allOptions.map(opt => ({
|
||||
label: "--" + opt.name,
|
||||
description: opt.type !== 'bool' ? opt.type === 'stringArray' ? '' : opt.default : undefined,
|
||||
detail: opt.description.charAt(0).toUpperCase() + opt.description.slice(1)
|
||||
})).filter(opt => !specialOptions.includes(opt.label));
|
||||
} catch (error: any) {
|
||||
options = [
|
||||
{
|
||||
label: Option.ActionCachePath,
|
||||
description: this.getCacheDirectory(['act']),
|
||||
@@ -305,6 +331,7 @@ export default class SettingsTreeDataProvider implements TreeDataProvider<Github
|
||||
detail: 'Enable verbose output.'
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
options.forEach((option, index) => {
|
||||
options[index].label = options[index].label.slice(2);
|
||||
|
||||
Reference in New Issue
Block a user