-
-
Notifications
You must be signed in to change notification settings - Fork 87
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
Fails to fallback to the default command if no argument is passed #94
Comments
This is unrelated to this issue, but is there any reason for exiting with the exit code 1 when asking for help with |
Well, as for the fallback command, this is by design, and mentioned here:
The intention was to allow a shorthand syntax, and not to hijack the "no arguments" situation. You can see a use case for it in rush, where you can run In other words, the You can see how it behaves by adding As for the help exiting with non zero, this is a side effect I need to check if can be changed. |
Thanks for the quick response. Right, understood. But is there any other way to create the "no argument" situation? I could convert all the commands to positional arguments and check if there were any arguments passed or not but that is not a good solution. Another thing I noticed is we cannot pass multiple flags with one hyphen. So, |
No arguments, as in the big majority of command line tools, shows short usage.
Right. Not supported at this time. I believe parsing for such a case is more effort than its worth. Also, don't forget that in some CLI apps, you can provide the argument of the short flag immediately after the short flag - for example All these are - by design - out of scope, due to the high priority I assign to simplicity. If there is a simple way to do it, I am open to it. |
Maybe a description would help, if not then I will try to create a YAML file. Assuming a CLI tool called Maybe, the One of my use case is that I have a script which upgrades all the tools and packages I have on my machine. If the script is called without any arguments, then everything should be upgraded, otherwise the specified tools/packages should be upgraded. |
Thanks. I understand the feature, and your "script that upgrades tools" remark helps me undertsnad the use case. Give me a few minutes to prepare an example or two of possible solutions. I will post a new comment when done. In the meantime, I have changed the |
Ok. Please take a look at https://github.com/DannyBen/bashly-support/tree/master/issue-94 There are two solutions there, that I think are intuitive, standards-compliant, and easy to write and maintain. Solution 1Treat your packages as arguments, not commands. It is semantically more correct I think. The sample code provided assumes that your tool is only responsible for upgrading stuff, but even if this is not the case, you can implement the same concept under In this solution, the package name is optional, and if not provided, will "run all". Solution 2If, for whatever reason, you really prefer to have your package names as commands, and not arguments, then there is no choice but to have a Solution 3 - Use rushSince I also faced your use case (or at least similar), in which I wanted an easy and reproducible way to install / upgrade everything on my system, I have created rush. This tool (created with bashly...) lets you write scripts that are doing whatever you want (in whatever language), and run them by doing The tool provides much more functionality, and you can see all the tools that I am personally installing with it in my personal rush-repo. Thought I'd mention it, in case it is also of interest to you. |
Thanks for providing comprehensive and multiple solutions. I tried exactly the same technique as you have provided in solution 1 and I'm happy with that. I have also added the
I believe the issue can be closed now. |
Excellent. And you are absolutely right - the If you need any help with bashly or rush, feel free to open an issue. My github issues philosophy, is that you can open support tickets :) Thanks for opening it, and as for the |
Yes, the documentation is well laid out.
No, it's not urgent. |
Well... something else came up, so version 0.6.4 is now live with the |
I might've misinterpreted the
default
key, but here's my use case:Assuming a CLI tool called
foo
, if I run./foo
without any arguments, it should run the default command as specified with thedefault
key, but instead it outputs the usage and exit.I think the reason is that in
parse_requirements
function, the default command comes after the fallback command, inverting the order fixes the issue:bashly/examples/command-default/ftp
Lines 194 to 204 in d149e53
The text was updated successfully, but these errors were encountered: