diff --git a/src/help/command.ts b/src/help/command.ts index 77ceab58..996e17da 100644 --- a/src/help/command.ts +++ b/src/help/command.ts @@ -203,6 +203,14 @@ export class CommandHelp extends HelpFormatter { if (flag.env) { metadata.push(`env: ${flag.env}`) } + + if ((flag as any).min !== undefined) { + metadata.push(`min: ${(flag as any).min}`) + } + + if ((flag as any).max !== undefined) { + metadata.push(`max: ${(flag as any).max}`) + } } else if (flag.type === 'boolean' && flag.env) { metadata.push(`env: ${flag.env}`) } diff --git a/test/help/format-command.test.ts b/test/help/format-command.test.ts index d43e1632..a3e3209d 100644 --- a/test/help/format-command.test.ts +++ b/test/help/format-command.test.ts @@ -1214,4 +1214,78 @@ FLAGS --myFlag= (required) [default: defaultValue, env: MY_FLAG] my flag`) }) }) + + describe('integer flags with min/max', () => { + it('should display min and max values', async () => { + const cmd = await makeLoadable( + makeCommandClass({ + id: 'test:minmax', + flags: { + port: flags.integer({ + description: 'port number', + min: 1024, + max: 65_535, + default: 3000, + }), + retries: flags.integer({ + description: 'retry attempts', + min: 0, + max: 10, + required: true, + }), + }, + }), + ) + + const output = help.formatCommand(cmd) + expect(output).to.equal(`USAGE + $ oclif test:minmax --retries [--port ] + +FLAGS + --port= [default: 3000, min: 1024, max: 65535] port number + --retries= (required) [min: 0, max: 10] retry attempts`) + }) + + it('should display only min when max is not set', async () => { + const cmd = await makeLoadable( + makeCommandClass({ + id: 'test:min', + flags: { + count: flags.integer({ + description: 'item count', + min: 1, + }), + }, + }), + ) + + const output = help.formatCommand(cmd) + expect(output).to.equal(`USAGE + $ oclif test:min [--count ] + +FLAGS + --count= [min: 1] item count`) + }) + + it('should display only max when min is not set', async () => { + const cmd = await makeLoadable( + makeCommandClass({ + id: 'test:max', + flags: { + limit: flags.integer({ + description: 'max items', + max: 100, + }), + }, + }), + ) + + const output = help.formatCommand(cmd) + expect(output).to.equal(`USAGE + $ oclif test:max [--limit ] + +FLAGS + --limit= [max: 100] max items`) + }) + }) })