Skip to content

Commit f6aaa81

Browse files
committed
chore!: remove flag for useFlagInstead
1 parent c59ae04 commit f6aaa81

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ API_KEY: test
6060

6161
## Preview
6262

63+
### 0.2.0
64+
65+
- Removed `flag` property for `useFlagInstead`
66+
6367
### 0.1.0
6468

6569
- Added documentation

SECURITY.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ Only the latest major version is actively maintained and receives security updat
88
| ------- | --------- |
99
| 0.x ||
1010

11-
<!-- For future reference -->
12-
<!-- | 0.x | ❌ | -->
13-
1411
## Reporting a Vulnerability
1512

1613
If you discover a security vulnerability in this project, please report it responsibly using one of the two listed methods. Do **not** create an issue about any vulnerabilities.
@@ -27,4 +24,4 @@ I prefer it if you [opened a GitHub security advisory](https://github.com/galvin
2724

2825
### Alternative Contact
2926

30-
If you do not wish to use GitHub, you may send an email to `imgalvin@pm.me` with the details of the issue
27+
If you do not wish to use GitHub, you may send an email to `contact@socialstats.app` with the details of the issue

package-lock.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@ export interface VariableDefinition<T = unknown> {
2727

2828
/**
2929
* Optional CLI flag (e.g., --token) that can be used instead of ENV.
30+
* @alias Removed `flag` property. Use this instead.
3031
*/
31-
flag?: string;
32+
useFlagInstead?: string;
33+
34+
/**
35+
* Only load the variable if this CLI flag is present.
36+
*/
37+
useWithFlag?: string;
3238

3339
/**
3440
* Whether to quit the process if a required variable is missing.
@@ -88,20 +94,20 @@ export class EnvManager<T extends ProjectVars = {}> {
8894
required = false,
8995
default: defVal,
9096
type = (v => v) as (val: string) => any,
91-
flag,
97+
useFlagInstead,
9298
quitOnMissing,
9399
} = def;
94100

95101
if (!result[project]) result[project] = {};
96102

97103
// First try CLI flag, then fallback to env var
98-
const raw = (flag && this.getFlagValue(flag)) || process.env[name];
104+
const raw = (useFlagInstead && this.getFlagValue(useFlagInstead)) || process.env[name];
99105

100106
if (raw === undefined || raw === "") {
101107
if (defVal !== undefined) {
102108
result[project][name] = defVal;
103109
} else if (required) {
104-
const msg = `Missing required variable/flag: ${name}${flag ? ` (flag: ${flag})` : ""}`;
110+
const msg = `Missing required variable/flag: ${name}${useFlagInstead ? ` (useFlagInstead: ${useFlagInstead})` : ""}`;
105111
if (quitOnMissing !== false) throw new Error(msg);
106112
else console.warn(msg);
107113
}

tests/index.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe("EnvManager", () => {
1313
const manager = new EnvManager()
1414
.add({
1515
name: "DISCORD_TOKEN",
16-
flag: "--discord-token",
16+
useFlagInstead: "--discord-token",
1717
type: String,
1818
project: "discordBot",
1919
required: true,
@@ -28,7 +28,7 @@ describe("EnvManager", () => {
2828
const manager = new EnvManager()
2929
.add({
3030
name: "PORT",
31-
flag: "--port",
31+
useFlagInstead: "--port",
3232
type: Number,
3333
project: "apiServer",
3434
default: 3000,
@@ -47,7 +47,7 @@ describe("EnvManager", () => {
4747
const manager = new EnvManager()
4848
.add({
4949
name: "PORT",
50-
flag: "--port",
50+
useFlagInstead: "--port",
5151
type: Number,
5252
project: "apiServer",
5353
required: false

0 commit comments

Comments
 (0)