options.flags.test.js
This file
Path
tests/options.flags.test.js
83 lines · 2.7 KiB · JavaScript
Last changed by
Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
History of this fileTake it
The walk stopped after 200 commits: lines older than f47bdf5 point at it.
Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 1–9why, one step back1const commander = require('../');23// Test the various ways flags can be specified in the first parameter to `.option`45test('when only short flag defined and not specified then value is undefined', () => {6 const program = new commander.Command();7 program8 .option('-p', 'add pepper');9 program.parse(['node', 'test']);Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 10why, one step back10 expect(program.opts().p).toBeUndefined();Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 11–17why, one step back11});1213test('when only short flag defined and specified then value is true', () => {14 const program = new commander.Command();15 program16 .option('-p', 'add pepper');17 program.parse(['node', 'test', '-p']);Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 18why, one step back18 expect(program.opts().p).toBe(true);Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 19–25why, one step back19});2021test('when only long flag defined and not specified then value is undefined', () => {22 const program = new commander.Command();23 program24 .option('--pepper', 'add pepper');25 program.parse(['node', 'test']);Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 26why, one step back26 expect(program.opts().pepper).toBeUndefined();Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 27–33why, one step back27});2829test('when only long flag defined and specified then value is true', () => {30 const program = new commander.Command();31 program32 .option('--pepper', 'add pepper');33 program.parse(['node', 'test', '--pepper']);Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 34why, one step back34 expect(program.opts().pepper).toBe(true);Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 35–41why, one step back35});3637test('when "short,long" flags defined and short specified then value is true', () => {38 const program = new commander.Command();39 program40 .option('-p,--pepper', 'add pepper');41 program.parse(['node', 'test', '-p']);Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 42why, one step back42 expect(program.opts().pepper).toBe(true);Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 43–49why, one step back43});4445test('when "short,long" flags defined and long specified then value is true', () => {46 const program = new commander.Command();47 program48 .option('-p,--pepper', 'add pepper');49 program.parse(['node', 'test', '--pepper']);Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 50why, one step back50 expect(program.opts().pepper).toBe(true);Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 51–57why, one step back51});5253test('when "short|long" flags defined and short specified then value is true', () => {54 const program = new commander.Command();55 program56 .option('-p|--pepper', 'add pepper');57 program.parse(['node', 'test', '-p']);Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 58why, one step back58 expect(program.opts().pepper).toBe(true);Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 59–65why, one step back59});6061test('when "short|long" flags defined and long specified then value is true', () => {62 const program = new commander.Command();63 program64 .option('-p|--pepper', 'add pepper');65 program.parse(['node', 'test', '--pepper']);Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 66why, one step back66 expect(program.opts().pepper).toBe(true);Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 67–73why, one step back67});6869test('when "short long" flags defined and short specified then value is true', () => {70 const program = new commander.Command();71 program72 .option('-p --pepper', 'add pepper');73 program.parse(['node', 'test', '-p']);Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 74why, one step back74 expect(program.opts().pepper).toBe(true);Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 75–81why, one step back75});7677test('when "short long" flags defined and long specified then value is true', () => {78 const program = new commander.Command();79 program80 .option('-p --pepper', 'add pepper');81 program.parse(['node', 'test', '--pepper']);Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71
line 82why, one step back82 expect(program.opts().pepper).toBe(true);Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
line 83why, one step back83});