Skip to content
Myr

help.commandUsage.test.js

This file

Path

tests/help.commandUsage.test.js

49 lines · 1.7 KiB · JavaScript

Last changed by

More consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9

History of this file

Take it

Refactor help internals into separate interface/class (#1365)John Geebefore adoption19ae912

lines 1–44why, one step back
1const commander = require('../');
23// These are tests of the Help class, not of the Command help.4// There is some overlap with the higher level Command tests (which predate Help).56describe('commandUsage', () => {7 test('when single program then "program [options]"', () => {8 const program = new commander.Command();9 program.name('program');10 const helper = new commander.Help();11 expect(helper.commandUsage(program)).toEqual('program [options]');12 });1314 test('when multi program then "program [options] [command]"', () => {15 const program = new commander.Command();16 program.name('program');17 program.command('sub');18 const helper = new commander.Help();19 expect(helper.commandUsage(program)).toEqual('program [options] [command]');20 });2122 test('when program has alias then usage includes alias', () => {23 const program = new commander.Command();24 program25 .name('program')26 .alias('alias');27 const helper = new commander.Help();28 expect(helper.commandUsage(program)).toEqual('program|alias [options]');29 });3031 test('when help for subcommand then usage includes hierarchy', () => {32 const program = new commander.Command();33 program34 .name('program');35 const sub = program.command('sub')36 .name('sub');37 const helper = new commander.Help();38 expect(helper.commandUsage(sub)).toEqual('program sub [options]');39 });4041 test('when program has argument then usage includes argument', () => {42 const program = new commander.Command();43 program44 .name('program')

More consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9

line 45why, one step back
45 .argument('<file>');

Refactor help internals into separate interface/class (#1365)John Geebefore adoption19ae912

lines 46–49why, one step back
46 const helper = new commander.Help();
47 expect(helper.commandUsage(program)).toEqual('program [options] <file>');48 });49});