Skip to content

Commit

Permalink
Support function switch for sls manage command
Browse files Browse the repository at this point in the history
  • Loading branch information
logandk committed Oct 22, 2024
2 parents f6eee36 + 8c80d58 commit 2d71715
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 69 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
env: {
es6: true,
node: true,
mocha: true,
},
extends: "eslint:recommended",
parserOptions: {
Expand Down
24 changes: 20 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,29 @@ class ServerlessWSGI {
}

findHandler() {
return _.findKey(this.serverless.service.functions, (fun) =>
_.includes(fun.handler, "wsgi_handler.handler")
);
const functionName = this.options.function || this.options.f;

if (functionName) {
// If the function name is specified, return it directly
if (this.serverless.service.functions[functionName]) {
return functionName;
} else {
throw new Error(`Function "${functionName}" not found.`);
}
} else {
return _.findKey(this.serverless.service.functions, (fun) =>
_.includes(fun.handler, "wsgi_handler.handler")
);
}
}

invokeHandler(command, data, local) {
const handlerFunction = this.findHandler();
let handlerFunction;
try {
handlerFunction = this.findHandler();
} catch (error) {
return BbPromise.reject(error.message);
}

if (!handlerFunction) {
return BbPromise.reject(
Expand Down
Loading

0 comments on commit 2d71715

Please sign in to comment.