Skip to content

🎥 Make videos programmatically with React

handle exit code

Jonny Burger6e8c97b88d20
diff --git a/packages/lambda/src/cli/args.ts b/packages/lambda/src/cli/args.ts
index b4fb0cccb8..20bac0d18c 100644
--- a/packages/lambda/src/cli/args.ts
+++ b/packages/lambda/src/cli/args.ts
@@ -35,4 +35,5 @@ export const forceFlagProvided =
parsedLambdaCli.yes ||
parsedLambdaCli.y;
-export const quietFlagProvided = parsedLambdaCli.quiet || parsedLambdaCli.q;
+export const quietFlagProvided = () =>
+ parsedLambdaCli.quiet || parsedLambdaCli.q;
diff --git a/packages/lambda/src/cli/commands/functions/ls.ts b/packages/lambda/src/cli/commands/functions/ls.ts
index f04588dc82..2a568ca5df 100644
--- a/packages/lambda/src/cli/commands/functions/ls.ts
+++ b/packages/lambda/src/cli/commands/functions/ls.ts
@@ -14,7 +14,7 @@ export const FUNCTIONS_LS_SUBCOMMAND = 'ls';
export const functionsLsCommand = async () => {
const region = getAwsRegion();
const fetchingOutput = CliInternals.createOverwriteableCliOutput();
- if (!quietFlagProvided) {
+ if (!quietFlagProvided()) {
fetchingOutput.update('Getting functions...');
}
@@ -23,7 +23,12 @@ export const functionsLsCommand = async () => {
compatibleOnly: false,
});
- if (quietFlagProvided) {
+ if (quietFlagProvided()) {
+ if (functions.length === 0) {
+ Log.info('()');
+ return;
+ }
+
Log.info(functions.map((f) => f.functionName).join(' '));
return;
}
diff --git a/packages/lambda/src/cli/commands/functions/rm.ts b/packages/lambda/src/cli/commands/functions/rm.ts
index a2079c4fd6..3cc704c2b5 100644
--- a/packages/lambda/src/cli/commands/functions/rm.ts
+++ b/packages/lambda/src/cli/commands/functions/rm.ts
@@ -13,7 +13,6 @@ export const FUNCTIONS_RM_SUBCOMMAND = 'rm';
const LEFT_COL = 16;
export const functionsRmCommand = async (args: string[]) => {
- const region = getAwsRegion();
if (args.length === 0) {
Log.error('No function name passed.');
Log.error(
@@ -25,6 +24,13 @@ export const functionsRmCommand = async (args: string[]) => {
quit(1);
}
+ if (args[0] === '()') {
+ Log.info('No functions to remove.');
+ return;
+ }
+
+ const region = getAwsRegion();
+
for (const functionName of args) {
const infoOutput = CliInternals.createOverwriteableCliOutput();
infoOutput.update('Getting function info...');
diff --git a/packages/lambda/src/cli/commands/sites/ls.ts b/packages/lambda/src/cli/commands/sites/ls.ts
index 55f3f9f06a..aecdae0626 100644
--- a/packages/lambda/src/cli/commands/sites/ls.ts
+++ b/packages/lambda/src/cli/commands/sites/ls.ts
@@ -23,18 +23,18 @@ export const sitesLsSubcommand = async () => {
const region = getAwsRegion();
const {sites, buckets} = await getSites({region});
- if (buckets.length > 1 && !quietFlagProvided) {
+ if (buckets.length > 1 && !quietFlagProvided()) {
Log.warn(
'Warning: You have more than one Remotion S3 bucket, but only one is needed. This can lead to conflicts. Remove all but one of them.'
);
}
const sitesPluralized = sites.length === 1 ? 'site' : 'sites';
- if (!quietFlagProvided) {
+ if (!quietFlagProvided()) {
Log.info(`${sites.length} ${sitesPluralized} in the ${region} region.`);
}
- if (quietFlagProvided) {
+ if (quietFlagProvided()) {
return Log.info(sites.map((s) => s.id).join(' '));
}
diff --git a/tests/lambda/cli.test.ts b/tests/lambda/cli.test.ts
index 47e9ba245b..966f2fac1a 100644
--- a/tests/lambda/cli.test.ts
+++ b/tests/lambda/cli.test.ts
@@ -1,3 +1,4 @@
+import { parsedLambdaCli } from "../../packages/lambda/src/cli/args";
import { LambdaInternals } from "../../packages/lambda/src/index";
import { getProcessStdErrOutput, getProcessWriteOutput } from "./console-hooks";
@@ -28,3 +29,14 @@ test("Deploy function and it already exists should fail", async () => {
/Error: Already found a function \(remotion-render-abcdef\) with version (.*) deployed in region us-east-1/
);
});
+
+test('If no functions are there and is quiet, should return "()"', async () => {
+ parsedLambdaCli.q = true;
+ await LambdaInternals.executeCommand(["functions", "ls"]);
+ expect(getProcessWriteOutput()).toBe("()");
+});
+
+test("Should handle functions rm called with no functions", async () => {
+ await LambdaInternals.executeCommand(["functions", "rm", "()"]);
+ expect(getProcessWriteOutput()).toBe("No functions to remove.");
+});
diff --git a/tests/lambda/console-hooks.ts b/tests/lambda/console-hooks.ts
index 12a0540594..30dccac29d 100644
--- a/tests/lambda/console-hooks.ts
+++ b/tests/lambda/console-hooks.ts
@@ -28,15 +28,15 @@ beforeEach(() => {
cleanFnStore();
// @ts-expect-error
process.stdout.write = (str: string) => {
- // originalStdout(str);
+ //originalStdout(str);
stdoutOutput.push(str);
};
console.log = (str: string) => {
- // originalStdout(str);
+ //originalStdout(str);
stdoutOutput.push(str);
};
console.error = (str: string) => {
- // originalStdErr(str);
+ //originalStderr(str);
stderrOutput.push(str);
};