feat(core): support reading NX_TUI_AUTO_EXIT env var (#30971)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior --tuiAutoExit doesn't support env vars ## Expected Behavior NX_TUI_AUTO_EXIT can set --tuiAutoExit ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
This commit is contained in:
parent
958985a182
commit
ac6d2beac0
@ -1,7 +1,7 @@
|
||||
import { readNxJson } from '../../config/nx-json';
|
||||
import { shouldUseTui } from '../../tasks-runner/is-tui-enabled';
|
||||
import { NxArgs } from '../../utils/command-line-utils';
|
||||
import { Argv, ParserConfigurationOptions } from 'yargs';
|
||||
import { Argv, coerce, ParserConfigurationOptions } from 'yargs';
|
||||
|
||||
interface ExcludeOptions {
|
||||
exclude: string[];
|
||||
@ -49,24 +49,24 @@ export interface TuiOptions {
|
||||
}
|
||||
|
||||
export function withTuiOptions<T>(yargs: Argv<T>): Argv<T & TuiOptions> {
|
||||
return yargs.options('tuiAutoExit', {
|
||||
describe:
|
||||
'Whether or not to exit the TUI automatically after all tasks finish, and after how long. If set to `true`, the TUI will exit immediately. If set to `false` the TUI will not automatically exit. If set to a number, an interruptible countdown popup will be shown for that many seconds before the TUI exits.',
|
||||
type: 'string',
|
||||
coerce: (value) => {
|
||||
if (value === 'true') {
|
||||
return true;
|
||||
return yargs
|
||||
.options('tuiAutoExit', {
|
||||
describe:
|
||||
'Whether or not to exit the TUI automatically after all tasks finish, and after how long. If set to `true`, the TUI will exit immediately. If set to `false` the TUI will not automatically exit. If set to a number, an interruptible countdown popup will be shown for that many seconds before the TUI exits.',
|
||||
type: 'string',
|
||||
coerce: (v) => coerceTuiAutoExit(v),
|
||||
})
|
||||
.middleware((args) => {
|
||||
if (args.tuiAutoExit !== undefined) {
|
||||
process.env.NX_TUI_AUTO_EXIT = args.tuiAutoExit.toString();
|
||||
} else if (process.env.NX_TUI_AUTO_EXIT) {
|
||||
args.tuiAutoExit = coerceTuiAutoExit(
|
||||
process.env.NX_TUI_AUTO_EXIT
|
||||
// have to cast here because yarg's typings do not account for the
|
||||
// coercion function
|
||||
) as unknown as string;
|
||||
}
|
||||
if (value === 'false') {
|
||||
return false;
|
||||
}
|
||||
const num = Number(value);
|
||||
if (!Number.isNaN(num)) {
|
||||
return num;
|
||||
}
|
||||
throw new Error(`Invalid value for --tui-auto-exit: ${value}`);
|
||||
},
|
||||
}) as Argv<T & TuiOptions>;
|
||||
}) as Argv<T & TuiOptions>;
|
||||
}
|
||||
|
||||
export function withRunOptions<T>(yargs: Argv<T>): Argv<T & RunOptions> {
|
||||
@ -394,3 +394,17 @@ export function readParallelFromArgsAndEnv(args: { [k: string]: any }) {
|
||||
return Number(args['parallel']);
|
||||
}
|
||||
}
|
||||
|
||||
const coerceTuiAutoExit = (value: string) => {
|
||||
if (value === 'true') {
|
||||
return true;
|
||||
}
|
||||
if (value === 'false') {
|
||||
return false;
|
||||
}
|
||||
const num = Number(value);
|
||||
if (!Number.isNaN(num)) {
|
||||
return num;
|
||||
}
|
||||
throw new Error(`Invalid value for --tui-auto-exit: ${value}`);
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user