-
-
Notifications
You must be signed in to change notification settings - Fork 95
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(cli): improve handling of forwarding args/flags #101
Conversation
10d6096
to
0ad7bba
Compare
Anyone watching the repo can probably tell that I'm at a total loss on why the build is failing. Anyone wanna give it a look and figure out what's up? I think somehow that |
I'm fairly confident that I've narrowed it down to |
Looks like my fork fixes the issue. Just waiting on this to be merged and released or finding another solution. |
Codecov Report
@@ Coverage Diff @@
## next #101 +/- ##
===================================
Coverage 100% 100%
===================================
Files 14 10 -4
Lines 246 286 +40
===================================
+ Hits 246 286 +40
Continue to review full report at Codecov.
|
Wahoo! This PR is ready for review finally! |
@@ -4,11 +4,6 @@ import runNPS from './run-nps' | |||
const fixturesPath = resolve(__dirname, './fixtures') | |||
|
|||
test( | |||
'without arguments', |
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.
I removed this because yargs help output is non-deterministic and based on the width of the terminal.
@@ -60,24 +60,15 @@ test('options: logLevel sets the log level', () => { | |||
}) | |||
}) | |||
|
|||
test('passes on additional arguments', () => { |
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.
We don't worry about this anymore. This is no longer a feature. If you want to pass arguments, put it in quotes. It's less confusing this way
@kentcdodds The changes look fine, but do you think it would look a clean syntax? nps 'build --foo' My 2 cents: I would still prefer to not have any special syntax for my cli commands and below would be better than above: nps build --foo |
Thanks for the review @addityasingh (I've added you to the contributors table as a reviewer!), |
-h, --help Show help [boolean] | ||
-v, --version Show version number [boolean] | ||
|
||
Examples: |
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.
Examples really shine through 👍
README.md
Outdated
##### scripts | ||
|
||
To run a script, you simply provide the name of the script like so: | ||
And you can run multiple scripts in series by simply adding more arguments. |
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.
Maybe change wording to: And you can run multiple scripts in series by simply adding more space-separated arguments.?
src/get-logger.js
Outdated
@@ -50,6 +52,16 @@ function getShouldLogFn(...acceptableValues) { | |||
acceptableValues = ['', 'debug', ...acceptableValues] |
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.
I think it's preferable to treat params (acceptableValues
) as const and not to override them, to avoid any kind of confusion in readability
src/get-logger.js
Outdated
} | ||
} | ||
|
||
function getLogLevel({silent, logLevel}) { |
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.
This whole function can be refactored as below:
const getLogLevel = ({silent, logLevel}) => silent ? 'disable' : logLevel
**What**: This migrates us from `commander` and `omelette` to `yargs` and in the process changes how we handle forwarding of arguments and flags. We no longer just arbitrarily forward arguments to every script. Also instead of comma separated scripts, they're simply separated by a space. If you want to pass args/flags to a script, then you put it in quotes. **Why**: Makes this more predicatble. Also `yargs` is more powerful in general anyway. **How**: Magic... Will comment inline...
I'm going to merge this now and publish a beta for the |
**What**: This migrates us from `commander` and `omelette` to `yargs` and in the process changes how we handle forwarding of arguments and flags. We no longer just arbitrarily forward arguments to every script. Also instead of comma separated scripts, they're simply separated by a space. If you want to pass args/flags to a script, then you put it in quotes. **Why**: Makes this more predicatble. Also `yargs` is more powerful in general anyway. **How**: Magic... Will comment inline...
I just updated and realised I can no longer pass down args as I was doing before: I guess this was just useful sometimes without having to create every possible option in package-scripts |
As noted in the release notes
:) |
What: This migrates us from
commander
andomelette
toyargs
and in the process changes how we handle forwarding of arguments and
flags. We no longer just arbitrarily forward arguments to every script.
Also instead of comma separated scripts, they're simply separated by a
space. If you want to pass args/flags to a script, then you put it in
quotes.
Why: Makes this more predictable. Also
yargs
is more powerful ingeneral anyway.
How: Magic... Will comment inline...
Closes #70 and #100