-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix #4: Removes 'function' prefix from CLI args #16
Conversation
src/index.ts
Outdated
enum NodeEnv { | ||
PRODUCTION = 'production', | ||
} | ||
|
||
const argv = minimist(process.argv, { | ||
string: ['port', 'function-target', 'function-signature-type'], | ||
string: [ENV_VARIABLE.PORT, FLAG.TARGET, FLAG.SIGNATURE_TYPE], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be FLAG.PORT
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/index.ts
Outdated
}); | ||
|
||
const CODE_LOCATION = process.cwd(); | ||
const PORT = argv['port'] || process.env.PORT || '8080'; | ||
const PORT = | ||
argv[ENV_VARIABLE.PORT] || process.env[ENV_VARIABLE.PORT] || '8080'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be argv[FLAG.PORT]
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
src/index.ts
Outdated
argv['function-signature-type'] || | ||
process.env.FUNCTION_SIGNATURE_TYPE || | ||
'http'; | ||
argv[FLAG.SIGNATURE_TYPE] || process.env.FUNCTION_SIGNATURE_TYPE || 'http'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be process.env[ENV_VARIABLE.SIGNATURE_TYPE]
, for consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/index.ts
Outdated
|
||
// Supported environment variables | ||
const ENV_VARIABLE = { | ||
PORT: 'FUNCTION_PORT', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be kept as PORT. It is not a functions-specific environment variable, and it comes from Knative runtime contract.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
const ENV_VARIABLE = { | ||
PORT: 'FUNCTION_PORT', | ||
TARGET: 'FUNCTION_TARGET', | ||
SIGNATURE_TYPE: 'FUNCTION_SIGNATURE_TYPE', // underscore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we are refactoring this, please replace FUNCTION_SIGNATURE_TYPE
in FUNCTION_SIGNATURE_TYPE must be one of 'http' or 'event'.
message below with Function signature type
, as it can refer to either flag or env var.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/index.ts
Outdated
}); | ||
|
||
const CODE_LOCATION = process.cwd(); | ||
const PORT = argv['port'] || process.env.PORT || '8080'; | ||
const PORT = | ||
argv[ENV_VARIABLE.PORT] || process.env[ENV_VARIABLE.PORT] || '8080'; | ||
const FUNCTION_TARGET = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I can see how the refactoring you are proposing makes sense, it also makes the code a bit less readable, in my opinion, because of the extra mappings. For example, we are mapping FUNCTION_TARGET
string to ENV_VARIABLE.TARGET
and then resolving it to FUNCTION_TARGET
const.
If the names without 'function' prefix are to be the canonical ones, then let's drop FUNCTION_
prefix from FUNCTION_TARGET
, FUNCTION_SIGNATURE_TYPE_STRING
, FUNCTION_SIGNATURE_TYPE
consts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dropped the FUNCTION_
prefix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this change now, please address the remaining comments. Thanks!
src/index.ts
Outdated
const FUNCTION_TARGET = | ||
argv['function-target'] || process.env.FUNCTION_TARGET || 'function'; | ||
const PORT = argv[FLAG.PORT] || process.env[ENV.PORT] || '8080'; | ||
const TARGET = argv[FLAG.TARGET] || process.env[ENV.TARGET] || 'function'; | ||
|
||
const FUNCTION_SIGNATURE_TYPE_STRING = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could drop FUNCTION_
prefix in this const as well, for consistency and brevity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This request is getting out of scope, but I've changed it as I agree.
src/index.ts
Outdated
argv['function-signature-type'] || | ||
process.env.FUNCTION_SIGNATURE_TYPE || | ||
'http'; | ||
argv[FLAG.SIGNATURE_TYPE] || process.env[ENV.SIGNATURE_TYPE] || 'http'; | ||
const FUNCTION_SIGNATURE_TYPE = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could drop FUNCTION_
prefix in this const as well, for consistency and brevity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/index.ts
Outdated
// Supported environment variables | ||
const ENV = { | ||
PORT: 'PORT', | ||
TARGET: 'TARGET', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps I wasn't clear in my previous comments: we should keep the environment variable names unchanged, just like in the table in README. Please keep PORT, FUNCTION_TARGET, FUNCTION_SIGNATURE_TYPE.
Short names are fine for flag names and const names in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean:
const ENV = {
PORT: 'PORT',
TARGET: 'FUNCTION_TARGET',
SIGNATURE_TYPE: 'FUNCTION_SIGNATURE_TYPE', // underscore
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Agreed.
Not sure why I changed this. Reverted the FUNCTION_
prefix for these env vars.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed comments. PTAL.
import * as http from 'http'; | ||
import * as onFinished from 'on-finished'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IDE auto-sorted.
import * as invoker from '../src/invoker'; | ||
import * as supertest from 'supertest'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IDE auto-sorted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! LGTM.
Fixes #4.
function
from CLI/env vars fortarget
andsignature-type