Skip to content

Parse rework for nested commands #1149

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

Merged
merged 38 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
01500af
First cut at parse rework
shadowspawn Jan 12, 2020
22c9ca5
Add check for requiredOption when calling executable subcommand
shadowspawn Jan 12, 2020
de0f20a
Set program name using supported approach
shadowspawn Jan 12, 2020
7dc2349
Add .addCommand, easy after previous work
shadowspawn Jan 13, 2020
5e43088
Add support for default command using action handler
shadowspawn Jan 13, 2020
d4f87b2
Add implicitHelpCommand and change help flags description
shadowspawn Jan 14, 2020
f51b0e3
Add implicit help command to help
shadowspawn Jan 14, 2020
e421524
Turn off implicit help command for most help tests
shadowspawn Jan 14, 2020
a257e49
.addHelpCommand
shadowspawn Jan 16, 2020
6b7a7c6
Remove addHelpCommand from tests and make match more narrow
shadowspawn Jan 18, 2020
b5b062c
Use test of complete default help output
shadowspawn Jan 18, 2020
3be5ba3
Add tests for whether implicit help appears in help
shadowspawn Jan 18, 2020
b4c055b
Add tests that help command dispatched to correct command
shadowspawn Jan 18, 2020
c455732
Add simple nested subcommand test
shadowspawn Jan 18, 2020
bb9fe74
Add default command tests for action based subcommand
shadowspawn Jan 18, 2020
f5b0798
Remove mainModule, out of scope for current PR
shadowspawn Jan 18, 2020
b28a088
Add legacy asterisk handling and tests
shadowspawn Jan 18, 2020
81185fe
Add more initialisation so object in known state
shadowspawn Jan 19, 2020
9d20c11
Tests for addCommand
shadowspawn Jan 19, 2020
460e3ec
Add first cut at enhanced default error detection
shadowspawn Jan 19, 2020
2a480a5
Add test that addCommand requires name
shadowspawn Jan 21, 2020
0736a77
Add block on automatic name generation for deeply nested executables
shadowspawn Jan 21, 2020
ae61194
Add block on automatic name generation for deeply nested executables
shadowspawn Jan 21, 2020
706b0f9
Merge branch 'feature/parse-rework' of github.com:shadowspawn/command…
shadowspawn Jan 21, 2020
d740db2
Fix describe name for tests
shadowspawn Jan 21, 2020
c529bff
Refine unknownCommand handling and add tests
shadowspawn Jan 21, 2020
365de99
Add suggestion to try help, when appropriate
shadowspawn Jan 21, 2020
aa3805d
Fix typo
shadowspawn Jan 22, 2020
4043f2b
Move common command configuration options in README, and add isDefaul…
shadowspawn Jan 22, 2020
24698c9
Add isDefault and example to README
shadowspawn Jan 22, 2020
cef94eb
Add nested commands
shadowspawn Jan 22, 2020
e5b68f4
Document .addHelpCommand, and tweaks
shadowspawn Jan 22, 2020
b980c2d
Remove old default command, and rework command:* example
shadowspawn Jan 22, 2020
30379ae
Document .addCommand
shadowspawn Jan 22, 2020
5fbec7e
Remove comment referring to removed code.
shadowspawn Jan 24, 2020
c0d62d3
Revert the error tip "try --help", not happy with the wording
shadowspawn Jan 27, 2020
fe896d1
Say "unknown command", like "unknown option"
shadowspawn Jan 27, 2020
432bb59
Set properties to null rather than undefined in constructor
shadowspawn Jan 28, 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
Add legacy asterisk handling and tests
  • Loading branch information
shadowspawn committed Jan 21, 2020
commit b28a0889a8a9913afda1d6488c0e1791d0813304
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -824,8 +824,12 @@ Command.prototype._parseCommand = function(operands, unknown) {
});

this._actionHandler(args);
// this.emit('command:' + this.name(), operands, unknown); // still needed????
} else {
this.emit('command:' + this.name(), operands, unknown); // retain ????
} else if (operands.length) {
// legacy behaviours, command and listener
if (this._findCommand('*')) {
this._dispatchSubcommand('*', operands, unknown);
}
this.emit('command:*', operands, unknown);
}
}
Expand Down
22 changes: 19 additions & 3 deletions tests/command.asterisk.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,30 @@ const commander = require('../');
//
// Historical: the event 'command:*' used to also be shared by the action handler on the program.

describe.skip(".command('*')", () => {
describe(".command('*')", () => {
// Use internal knowledge to suppress output to keep test output clean.
let writeMock;

beforeAll(() => {
writeMock = jest.spyOn(process.stdout, 'write').mockImplementation(() => { });
});

afterAll(() => {
writeMock.mockRestore();
});

test('when no arguments then asterisk action not called', () => {
const mockAction = jest.fn();
const program = new commander.Command();
program
.exitOverride() // to catch help
.command('*')
.action(mockAction);
program.parse(['node', 'test']);
try {
program.parse(['node', 'test']);
} catch (err) {
;
}
expect(mockAction).not.toHaveBeenCalled();
});

Expand Down Expand Up @@ -58,7 +74,7 @@ describe.skip(".command('*')", () => {
});

// Test .on explicitly rather than assuming covered by .command
describe.skip(".on('command:*')", () => {
describe(".on('command:*')", () => {
test('when no arguments then listener not called', () => {
const mockAction = jest.fn();
const program = new commander.Command();
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