-
-
Notifications
You must be signed in to change notification settings - Fork 84
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
[Feature] Support allowed argument values as an option #65
Comments
I am happy to hear that other people make good use of bashly, thanks for sharing that. While I can see the value of what you are proposing, my initial reaction is that this is something that is better handled by the application space, rather than the framework space. Why I think it should be handled by the user-domain applicationNote that even in your question, you wanted to show a friendly error to the user:
So, if this kind of feature is handled by the framework, it will require doing quite a few things. Such as, handle the help message accordingly, perhaps alter the usage text, add the same kind of feature to the positional arguments, and possibly more. Also keep in mind, one of bashly's objectives is to be easy to learn, and easy to configure. I intentionally created a minimal set of tools - so much so, that some "features" were excvluded and can be opt in by calling How I propose to do it (without any change to bashly).I think you can still implement what you want, with ease, and without "copy pasting" code around. You can even do so in a way that is easy to then copy the solution between your different scripts. Here is what I suggest: Step 1: Initialize a script workspace with functions lib$ bashly init --minimal
$ bashly add lib # this just creates a sample function in `./sec/lib` Step 2: Update bashly.yml with a sample flag+argument# bashly.yml
name: login
help: Sample minimal application without commands
version: 0.1.0
args:
- name: site
help: Site to login to
flags:
- long: --user
short: -u
arg: NAME
help: "User name. Allowed: user, admin" Step 3: Create the
|
@DannyBen : Thanks for the reply. I already make use of library scripts to make this work and it does the job just fine. Since Bashly already provides this flexibility, I am fine with not bundling this into the framework if it increases complexity. |
Ok - let's keep this open for now, so we can think about it a little. If you have further details or suggestions on implementation (for example, error message configuration - needed or not?), please share. |
A generic message template along the lines of |
Alright. You are familiar with So, if we implement this feature, the message will at least be customizable in the same way - although not sure it will be able to say "Invalid role" - since this means it must be configured in the bashly.yml. |
I think we can perhaps add this functionality without any major disruption. |
Currently, I'm using the Rubygem version but I am fine with testing with the docker version separately as well. |
Excellent. Actually its easier for both of us to test the gem directly. |
Alright - I believe it is ready for your second opinion. To test it (either in a new empty folder, or directly in your bashly workspace): Create this Gemfile # Gemfile
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem "bashly", github: 'DannyBen/bashly', branch: 'add/flag-whitelist' Run You can use this initial # bashly.yml
name: login
help: Sample minimal application without commands
version: 0.1.0
args:
- name: site
help: Site to login to
flags:
- long: --user
short: -u
arg: NAME
allowed: [user, admin]
# required: true
default: user
help: User name You can see more details in the PR notes |
Tested the change and works perfectly fine for flags 🎉 . Thanks. |
Funny. I was about to ask you if you think it is needed there as well. |
I merged the PR to master, and opened a new issue to track the args implementation. |
Thanks a lot - I didn't check yet but was the Rubygem updated with the feature for flags already? |
Not yet - if you can wait a little longer (hours not days), I will have a release with args as well. For now, you can use the same Gemfile, only use branch I am also going to change the implementation a little (internals only) to be easier to maintain, and to add the args. Should be ready real soon. |
First of all, I cannot sing the praises of
bashly
enough - I have been using it heavily for a BASH CLI in my project for quite some time now and it just works.One feature that I'd like to see personally is support for allowed options for arguments. For example, a suggestion for the
bashly.yml
could look like:The behaviour I am expecting is:
✔️
login admin
✔️
login user
❌
login anythingelse
- this could fail with an error message likeInvalid role - allowed values are "admin" and "user"
The text was updated successfully, but these errors were encountered: