Skip to content

Commit e462264

Browse files
committed
fix(lesy-plugin-validator): return middleware data
1 parent 5f9ab1d commit e462264

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

packages/plugins/lesy-plugin-validator/__tests__/validator.middleware.test.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ describe("@lesy/lesy-plugin-validator", () => {
1212
commands: [
1313
{
1414
name: "hello",
15-
description: "this is hello desc",
16-
usage: "--foo--",
1715
args: {
1816
name: {
1917
required: true,
@@ -24,6 +22,15 @@ describe("@lesy/lesy-plugin-validator", () => {
2422
console.log(`Hello ${args.name}`);
2523
},
2624
},
25+
{
26+
name: "sayname",
27+
args: {
28+
name: {},
29+
},
30+
run: ({ args }) => {
31+
console.log(`Hi ${args.name || "Stranger"}`);
32+
},
33+
},
2734
],
2835
middlewares: [resolve(__dirname, "../src/validator.middleware.ts")],
2936
});
@@ -53,4 +60,9 @@ describe("@lesy/lesy-plugin-validator", () => {
5360
const response = await testBed.run(["hello"]);
5461
expect(response).toContain("Hello yogo");
5562
});
63+
64+
it("should not prompt for non required aargs", async () => {
65+
const response = await testBed.run(["sayname"]);
66+
expect(response).toContain("Hi Stranger");
67+
});
5668
});

packages/plugins/lesy-plugin-validator/src/validator.middleware.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
export default {
22
on: "PRE_VALIDATE",
3-
async run({ runningCommand: cmd, args, feature }) {
4-
console.log("***", feature);
3+
async run(ctx) {
4+
const { runningCommand: cmd, args, feature } = ctx;
55
const missingValues = [];
6-
let newArgs = cmd.args;
6+
let newArgs = args;
77
Object.keys(cmd.args).forEach((key: any) => {
8-
if (!args[key]) {
8+
if (cmd.args[key].required && !args[key]) {
99
missingValues.push(key);
1010
}
1111
});
@@ -27,6 +27,7 @@ export default {
2727
const ans = await feature.prompt(questions);
2828
newArgs = { ...args, ...ans };
2929
}
30-
return { cmd, args: newArgs };
30+
ctx.args = newArgs;
31+
return ctx;
3132
},
3233
};

0 commit comments

Comments
 (0)