Commit 90193df2 authored by mergify[bot]'s avatar mergify[bot] Committed by GitHub

Merge pull request #4401 from ethereum-optimism/sc/cmn-use-env-argv

feat(cmn): allow BSv2 to ignore env/argv
parents ae951300 eceb0de1
---
'@eth-optimism/common-ts': patch
---
Adds new standard options to disable parsing variables from environment and command line.
......@@ -158,6 +158,11 @@ export abstract class BaseServiceV2<
// commander for anything besides the ability to run `ts-node ./service.ts --help`.
const program = new Command()
for (const [optionName, optionSpec] of Object.entries(params.optionsSpec)) {
// Skip options that are not meant to be used by the user.
if (['useEnv', 'useArgv'].includes(optionName)) {
continue
}
program.addOption(
new Option(`--${optionName.toLowerCase()}`, `${optionSpec.desc}`).env(
`${opSnakeCase(
......@@ -197,8 +202,8 @@ export abstract class BaseServiceV2<
dotenv.config()
const config = new Config(params.name)
config.load({
env: true,
argv: true,
env: params.options?.useEnv ?? true,
argv: params.options?.useEnv ?? true,
})
// Clean configuration values using the options spec.
......
......@@ -30,6 +30,8 @@ export type StandardOptions = {
port?: number
hostname?: string
logLevel?: LogLevel
useEnv?: boolean
useArgv?: boolean
}
/**
......@@ -60,6 +62,18 @@ export const stdOptionsSpec: OptionsSpec<StandardOptions> = {
default: 'debug',
public: true,
},
useEnv: {
validator: validators.bool,
desc: 'For programmatic use, whether to use environment variables',
default: true,
public: true,
},
useArgv: {
validator: validators.bool,
desc: 'For programmatic use, whether to use command line arguments',
default: true,
public: true,
},
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment