Skip to content

parseOptions rework phase 2 #1145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
898a218
Remove openIssues test for #1062, fixed and being tested
shadowspawn Jan 4, 2020
dc48063
Rework parseOptions handling of unknown arguments
shadowspawn Jan 5, 2020
f978b77
First tests for parseOptions, enable prepared regression tests
shadowspawn Jan 5, 2020
3b3f8c0
Add tests for parseOptions
shadowspawn Jan 5, 2020
450eba4
Add tests on program.args after calling parse
shadowspawn Jan 5, 2020
36243bc
Minor update to README for changed parse behaviour
shadowspawn Jan 5, 2020
306eb2e
Merge branch 'release/5.x' into feature/parseOptions-rework
shadowspawn Jan 7, 2020
97c3f79
Add tests for Utility Conventions before changing code to match
shadowspawn Jan 7, 2020
96758be
Switch from preflight including normalise to just testing parseOptions
shadowspawn Jan 8, 2020
d7da74a
Only refactor known options
shadowspawn Jan 8, 2020
2a7a351
Add short flag processing to READMEm, and literal --
shadowspawn Jan 9, 2020
a342bd6
Improve character description
shadowspawn Jan 9, 2020
9012ce0
Add a note that options not positional.
shadowspawn Jan 10, 2020
a6bf6dd
Remove regression tests for bug not really fixed by this
shadowspawn Jan 10, 2020
5340525
Add back #561 into known issues
shadowspawn Jan 10, 2020
573a12d
Refactor to make a little clearer and symmetrical
shadowspawn Jan 10, 2020
8d9870b
Use template to construct strings consistently within parseOptions
shadowspawn Jan 10, 2020
efd8dbf
Merge branch 'release/5.x' into feature/normalize-rework
shadowspawn Jan 15, 2020
ebccd26
Fix example parsing
shadowspawn Jan 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Switch from preflight including normalise to just testing parseOptions
  • Loading branch information
shadowspawn committed Jan 8, 2020
commit 96758be7e626eab313bc1fc7ca2f93c0277c9daa
24 changes: 8 additions & 16 deletions tests/command.parseOptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,64 +245,56 @@ describe('Utility Conventions', () => {

test('when program has combo known boolean short flags then arg removed', () => {
const program = createProgram();
const normalized = program.normalize(['-ab']);
const result = program.parseOptions(normalized);
const result = program.parseOptions(['-ab']);
expect(result).toEqual({ operands: [], unknown: [] });
expect(program.opts()).toEqual({ aaa: true, bbb: true });
});

test('when program has combo unknown short flags then arg preserved', () => {
const program = createProgram();
const normalized = program.normalize(['-pq']);
const result = program.parseOptions(normalized);
const result = program.parseOptions(['-pq']);
expect(result).toEqual({ operands: [], unknown: ['-pq'] });
expect(program.opts()).toEqual({ });
});

test('when program has combo known short option and required value then arg removed', () => {
const program = createProgram();
const normalized = program.normalize(['-cvalue']);
const result = program.parseOptions(normalized);
const result = program.parseOptions(['-cvalue']);
expect(result).toEqual({ operands: [], unknown: [] });
expect(program.opts()).toEqual({ ccc: 'value' });
});

test('when program has combo known short option and optional value then arg removed', () => {
const program = createProgram();
const normalized = program.normalize(['-dvalue']);
const result = program.parseOptions(normalized);
const result = program.parseOptions(['-dvalue']);
expect(result).toEqual({ operands: [], unknown: [] });
expect(program.opts()).toEqual({ ddd: 'value' });
});

test('when program has known combo short boolean flags and required value then arg removed', () => {
const program = createProgram();
const normalized = program.normalize(['-abcvalue']);
const result = program.parseOptions(normalized);
const result = program.parseOptions(['-abcvalue']);
expect(result).toEqual({ operands: [], unknown: [] });
expect(program.opts()).toEqual({ aaa: true, bbb: true, ccc: 'value' });
});

test('when program has known combo short boolean flags and optional value then arg removed', () => {
const program = createProgram();
const normalized = program.normalize(['-abdvalue']);
const result = program.parseOptions(normalized);
const result = program.parseOptions(['-abdvalue']);
expect(result).toEqual({ operands: [], unknown: [] });
expect(program.opts()).toEqual({ aaa: true, bbb: true, ddd: 'value' });
});

test('when program has known long flag=value then arg removed', () => {
const program = createProgram();
const normalized = program.normalize(['--ccc=value']);
const result = program.parseOptions(normalized);
const result = program.parseOptions(['--ccc=value']);
expect(result).toEqual({ operands: [], unknown: [] });
expect(program.opts()).toEqual({ ccc: 'value' });
});

test('when program has unknown long flag=value then arg preserved', () => {
const program = createProgram();
const normalized = program.normalize(['--rrr=value']);
const result = program.parseOptions(normalized);
const result = program.parseOptions(['--rrr=value']);
expect(result).toEqual({ operands: [], unknown: ['--rrr=value'] });
expect(program.opts()).toEqual({ });
});
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy