-
Notifications
You must be signed in to change notification settings - Fork 884
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
fix: --verbose
option not working for run-ios
#1571
Closed
liamjones
wants to merge
1
commit into
react-native-community:main
from
liamjones:fix-run-ios-ignoring-verbose-flag
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import commander from 'commander'; | ||
import {attachCommand} from '../index'; | ||
|
||
jest.mock('@react-native-community/cli-config', () => ({ | ||
commands: [], | ||
})); | ||
|
||
describe('attachCommand', () => { | ||
it('should not pass verbose flag to sub-commands with their own verbose flag, given flag not set', () => { | ||
const commandFunction = jest.fn(); | ||
const command = { | ||
name: 'command-with-verbose-option', | ||
func: commandFunction, | ||
options: [ | ||
{name: '--verbose'}, | ||
{name: '--other-option-set'}, | ||
{name: '--other-option-not-set'}, | ||
], | ||
}; | ||
attachCommand(command); | ||
|
||
const argv = [ | ||
'node', | ||
'index.ts', | ||
'command-with-verbose-option', | ||
'--other-option-set', | ||
]; | ||
commander.parse(argv); | ||
|
||
expect(commandFunction).toBeCalledWith(expect.any(Object), undefined, { | ||
verbose: undefined, | ||
otherOptionSet: true, | ||
otherOptionNotSet: undefined, | ||
}); | ||
}); | ||
|
||
it('should pass verbose flag to sub-commands with their own verbose flag, given flag set', () => { | ||
const commandFunction = jest.fn(); | ||
const command = { | ||
name: 'command-with-verbose-option', | ||
func: commandFunction, | ||
options: [ | ||
{name: '--verbose'}, | ||
{name: '--other-option-set'}, | ||
{name: '--other-option-not-set'}, | ||
], | ||
}; | ||
attachCommand(command); | ||
|
||
const argv = [ | ||
'node', | ||
'index.ts', | ||
'command-with-verbose-option', | ||
'--verbose', | ||
'--other-option-set', | ||
]; | ||
commander.parse(argv); | ||
|
||
expect(commandFunction).toBeCalledWith(expect.any(Object), undefined, { | ||
verbose: true, | ||
otherOptionSet: true, | ||
otherOptionNotSet: undefined, | ||
}); | ||
}); | ||
|
||
it('should not pass verbose flag to sub-commands without their own verbose flag, given flag set', () => { | ||
const commandFunction = jest.fn(); | ||
const command = { | ||
name: 'command-without-verbose-option', | ||
func: commandFunction, | ||
options: [{name: '--other-option-set'}, {name: '--other-option-not-set'}], | ||
}; | ||
attachCommand(command); | ||
|
||
const argv = [ | ||
'node', | ||
'index.ts', | ||
'command-without-verbose-option', | ||
'--verbose', | ||
'--other-option-set', | ||
]; | ||
commander.parse(argv); | ||
|
||
expect(commandFunction).toBeCalledWith(expect.any(Object), undefined, { | ||
otherOptionSet: true, | ||
otherOptionNotSet: undefined, | ||
}); | ||
expect(commandFunction.mock.calls[0][2]).not.toHaveProperty('verbose'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commander is now at v9. Is this fix relevant then? If so, please update the comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I wasn't aware commander had been upgraded, that's good! 😄 That does potentially change things a bit.
How that affects the direction of the PR will depend a bit on how the core maintainers want things to work overall in the CLI. Some of the routes now open to us would affect option parsing across all commands.
Firstly, I believe the current workarounds would still work in the new version of commander but I've not tested them yet.
As for alternatives, there are multiple option parsing methods in the newer version of commander which are potentially relevant (full docs w/ examples);
.enablePositionalOptions()
So, if this was enabled
react-native --verbose run-ios
would be different toreact-native run-ios --verbose
. I guess you could also specifyreact-native --verbose run-ios --verbose
to up the verbosity at both levels?.passThroughOptions()
This one might also be relevant but I'm not sure how it would behave in the CLI until I have a chance to play with it (due to the dynamic
attachCommand
setup).Also, in this specific situation with
--verbose
I don't yet know if the recognised options (e.g. top level--verbose
) still get hidden from the pass-through.Is there a preferred way the core maintainers would like the options to behave in the CLI? If so I can look at changing the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I think we can use
enablePositionalOptions()
, this fixes this issue and we don't need to make workarounds.