diff --git a/lib/usage.ts b/lib/usage.ts index ba54cbcde..6bacf5320 100644 --- a/lib/usage.ts +++ b/lib/usage.ts @@ -163,14 +163,17 @@ export function usage(yargs: YargsInstance, shim: PlatformShim) { wrap = cols; }; - function getWrap() { + self.getWrap = () => { + if (shim.getEnv('YARGS_DISABLE_WRAP')) { + return null; + } if (!wrapSet) { wrap = windowWidth(); wrapSet = true; } return wrap; - } + }; const deferY18nLookupPrefix = '__yargsString__:'; self.deferY18nLookup = str => deferY18nLookupPrefix + str; @@ -202,7 +205,7 @@ export function usage(yargs: YargsInstance, shim: PlatformShim) { }, {} as Dictionary) ); - const theWrap = getWrap(); + const theWrap = self.getWrap(); const ui = shim.cliui({ width: theWrap, wrap: !!theWrap, @@ -769,6 +772,7 @@ export interface UsageInstance { getPositionalGroupName(): string; getUsage(): [string, string][]; getUsageDisabled(): boolean; + getWrap(): number | nil; help(): string; reset(localLookup: Dictionary): UsageInstance; showHelp(level?: 'error' | 'log' | ((message: string) => void)): void; diff --git a/test/usage.cjs b/test/usage.cjs index a7c888143..31138889d 100644 --- a/test/usage.cjs +++ b/test/usage.cjs @@ -1912,7 +1912,16 @@ describe('usage tests', () => { // the long description should cause several line // breaks when wrapped. - r.errors[0].split('\n').length.should.gte(4); + r.errors[0].split('\n').length.should.gte(5); + }); + + it('should not wrap when YARGS_DISABLED_WRAP is provided', () => { + const yargsInstance = yargs().wrap(99); + process.env.YARGS_DISABLE_WRAP = 'true'; + expect( + yargsInstance.getInternalMethods().getUsageInstance().getWrap() + ).to.equal(null); + delete process.env.YARGS_DISABLE_WRAP; }); it('should not raise an exception when long default and description are provided', () =>