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
Is it possible to create a command that only runs when no positional argument is specified? #1621
Comments
I think you can leverage the middlewares api to achieve this. That is, you can bind a middleware to a specific command and have it execute whatever logic you want given the desired conditions (i.e. no positional arguments). In a similar fashion, but with obvious performance trade-offs, you can bind a middleware function to every cli command. There might be other approachS to achieve the desired outcome but this I think will satisfy the requirements. |
@aorinevo I'm not sure how middleware could be used here. If you mean that I could manually handle all of the commands and options through the middleware functions, then yargs' argument parsing capabilities aren't being utilized and I might as well do everything manually. Would there be any way to handle only cases in which no positional arguments are specified? |
@cameronus What about using |
@mleguen Unfortunately
Running |
Well, it should. I'm fixing this. |
I am attempting to offer the following commands:
I can achieve the functionality of the first command (with no positional argument specified) using the default command handler, but this means it is also accessible using any other random positional arguments, like:
This would also trigger the default command handler, instead of an error warning the user that this command does not exist (which I would like). Would it be possible to achieve the behavior I am seeking?
The text was updated successfully, but these errors were encountered: