Skip to content

Commit 53c5205

Browse files
committed
Start of support for actions.json
Signed-off-by: worksofliam <mrliamallan@live.co.uk>
1 parent d9fcffa commit 53c5205

File tree

4 files changed

+85
-3
lines changed

4 files changed

+85
-3
lines changed

cli/src/builders/environment.ts

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface Action {
3232
name: string;
3333
command: string;
3434
extensions?: string[];
35+
environment?: "ile";
3536
}
3637

3738
export function getBranchLibraryName(currentBranch: string) {

cli/src/builders/iProject.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { CompileData, CommandParameters, CompileAttribute, getDefaultCompiles } from "./environment";
1+
import { fromCl } from "../utils";
2+
import { CompileData, CommandParameters, CompileAttribute, getDefaultCompiles, Action, getObjectType } from "./environment";
23

34
export class iProject {
45
includePaths?: string[] = [];
@@ -32,4 +33,18 @@ export class iProject {
3233
}
3334
}
3435
}
36+
37+
applyAction(newAction: Action) {
38+
if (newAction.environment && newAction.environment === `ile` && newAction.extensions && newAction.extensions.length > 0) {
39+
if (!newAction.extensions.includes(`GLOBAL`)) {
40+
const firstExt = newAction.extensions[0].toLowerCase();
41+
const becomesObject = getObjectType(firstExt);
42+
const commandData = fromCl(newAction.command);
43+
this.compiles[firstExt] = {
44+
becomes: becomesObject,
45+
...commandData
46+
};
47+
}
48+
}
49+
}
3550
}

cli/src/utils.ts

+43-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as fs from "fs";
66
import * as path from "path";
77
import * as os from "os"
88
import { ILEObject, ObjectType } from "./targets";
9+
import { CommandParameters } from "./builders/environment";
910

1011
export function getSystemNameFromPath(inputName: string) {
1112

@@ -156,13 +157,54 @@ export function getReferenceObjectsFrom(content: string) {
156157
return pseudoObjects;
157158
}
158159

160+
export function fromCl(cl: string): {command: string, parameters: CommandParameters} {
161+
let gotCommandnName = false;
162+
let parmDepth = 0;
163+
164+
let currentCommand = ``;
165+
let currentParmName = ``;
166+
let currentParmValue = ``;
167+
let parameters: CommandParameters = {};
168+
169+
for (const c of cl.split(``)) {
170+
if (c === `(`) {
171+
parmDepth++;
172+
if (parmDepth === 1) {
173+
}
174+
} else if (c === `)`) {
175+
if (parmDepth === 1) {
176+
parameters[currentParmName.toLowerCase()] = currentParmValue;
177+
currentParmValue = ``;
178+
currentParmName = ``;
179+
}
180+
parmDepth--;
181+
} else if (c === ` ` && !gotCommandnName) {
182+
gotCommandnName = true;
183+
currentCommand = currentCommand.trim();
184+
} else if (c === ` ` && gotCommandnName) {
185+
currentParmName = currentParmName.trim();
186+
} else if (parmDepth > 0) {
187+
currentParmValue += c;
188+
} else if (gotCommandnName) {
189+
currentParmName += c;
190+
} else {
191+
currentCommand += c;
192+
}
193+
}
194+
195+
return {
196+
command: currentCommand,
197+
parameters
198+
}
199+
}
200+
159201
/**
160202
*
161203
* @param command Optionally qualified CL command
162204
* @param parameters A key/value object of parameters
163205
* @returns Formatted CL string
164206
*/
165-
export function toCl(command: string, parameters?: { [parameter: string]: string }) {
207+
export function toCl(command: string, parameters?: CommandParameters) {
166208
let cl = command;
167209

168210
if (parameters) {

cli/test/environment.test.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { assert, describe, expect, test } from 'vitest'
22
import { getBranchLibraryName } from '../src/builders/environment';
3-
import { getReferenceObjectsFrom, getSystemNameFromPath } from '../src/utils';
3+
import { fromCl, getReferenceObjectsFrom, getSystemNameFromPath } from '../src/utils';
44

55
describe(`Deterministic branch name`, () => {
66
test('Basic name', () => {
@@ -64,6 +64,30 @@ describe(`Deterministic system name`, () => {
6464
})
6565
});
6666

67+
describe(`CL parser`, () => {
68+
test('Basic command', () => {
69+
const cl = `CRTCLPGM PGM(MYLIB/MYCL) SRCFILE(MYLIB/QCLSRC) SRCMBR(MYCL)`;
70+
const parsed = fromCl(cl);
71+
72+
console.log(parsed);
73+
expect(parsed.command).toBe(`CRTCLPGM`);
74+
expect(parsed.parameters).toMatchObject({
75+
pgm: `MYLIB/MYCL`,
76+
srcfile: `MYLIB/QCLSRC`,
77+
srcmbr: `MYCL`
78+
});
79+
});
80+
81+
test('Just command', () => {
82+
const cl = `CRTCLPGM`;
83+
const parsed = fromCl(cl);
84+
85+
console.log(parsed);
86+
expect(parsed.command).toBe(`CRTCLPGM`);
87+
expect(parsed.parameters).toMatchObject({});
88+
});
89+
});
90+
6791
describe(`Reference files`, () => {
6892
test('content', () => {
6993
const lines = [

0 commit comments

Comments
 (0)