-
-
Notifications
You must be signed in to change notification settings - Fork 90
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
Allow flags for commands that have subcommands #258
Comments
You mean having both subcommands and flags? Share more details, and possibly a command line example so I can help. |
Thanks for the prompt response. Perhaps the best motivating example is a Docker style CLI, where there are flags at the $ docker --help
Usage: docker [OPTIONS] COMMAND
A self-sufficient runtime for containers
Options:
--config string Location of client config files (default "/home/dev/.docker")
-c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST
env var and default context set with "docker context use")
-D, --debug Enable debug mode
-H, --host list Daemon socket(s) to connect to
-l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default "/home/dev/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/home/dev/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/home/dev/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
Management Commands:
builder Manage builds
buildx* Docker Buildx (Docker Inc., 0.9.1+azure-1)
.... Likewise, the sub-commands have flags/options $ docker attach --help
Usage: docker attach [OPTIONS] CONTAINER
Attach local standard input, output, and error streams to a running container
Options:
--detach-keys string Override the key sequence for detaching a container
--no-stdin Do not attach STDIN
--sig-proxy Proxy all received signals to the process (default true)
and also sub-sub-commands have flags/options $ docker builder build --help
Usage: docker builder build [OPTIONS] PATH | URL | -
Build an image from a Dockerfile
Options:
--add-host list Add a custom host-to-IP mapping (host:ip)
--build-arg list Set build-time variables
... I had thought to try use env variables in place of flags but that becomes cumbersome for sub-sub- etc. commands. Example:
Appreciate any thoughts. |
Right. Everything you mentioned can be done with bashly, with the exception of flags that do not belong to any command. Sub commands, and sub-sub(-sub...)-commands - can have their own arguments and flags of course. Personally, I find these general flags confusing (I mean why is At this point, this is not possible - I need to dig deeper into the code to see if this limitation can be lifted without complications. |
Thanks for taking this into consideration. There is also an elegance to allowing a parent flag to apply to all child commands? Maybe Am I correct in saying this behavior does not apply to the environment configuration? |
While there may be elegance to it, you need to remember that this is a Ruby script that generates a bash script.... :) There are limits to what can be done while still keeping the code clean and maintainable. After all, you must agree that the generated bashly script already supports quite a few nuances, that are sometimes even hard to achieve in a "normal" programming language. What I am considering is allowing things like this: $ cli --global-flags subcommand --subcommand-flags
# and maybe:
$ cli --global-flags subcommand --subcommand-global-flags sub-subcommand --sub-sub-flags In other words, flags that are defined on a command that has subcommands, will cascade down to everything below it, This will be in line with what the docker cli provides. I think that this can be achieved with an acceptable amount of effort.
Unless I misunderstand this statement, I don't think we will have a problem at all, nor will we need
Environment variables can be defined in any command (regardless of if they have subcommands or not). Does this make sense? |
Sounds reasonable. Order of precedence would be that child defaults and values override any parent values? |
I am unsure yet, but as I understand it now:
From your questions, I am not 100% we envision the same thing, so to clarify. Consider this YAML (which is not possible today): name: cli
help: Sample application
version: 0.1.0
# This section might be called `global_flags` - not sure yet.
flags:
- long: --force
short: -f
help: Overwrite existing files
commands:
- name: download
alias: d
help: Download a file
args:
- name: source
help: URL to download from
flags:
- long: --user
short: -u
help: Username to use for logging in In this case, running Running just |
Thanks for engaging.
Fair enough. However, |
I believe we do. |
I feel this is a bad form, but I believe the implementation I have in mind will accommodate this mutation. |
Interesting: Could this be configurable? |
Unlikely. I feel this is pushing it way too far. However - I cannot say for certain how (and at this point, if) it will be implemented. |
Agreed it is contrived. But, |
Yet, running |
I never followed which output is sent to stdout and which to stderr. What I meant in my previous comment, is that since there is nothing that handles I, for one, do not like that The fact that other CLIs do something does not make it right. |
Yeah, unfortunately we don't have the freedom to choose and must fit into the existing/surrounding infra, practices and conventions. |
Or be the pioneers in changing them :) |
I believe option handling would be aided by this: |
This is now implemented in the master branch and will be released soon. If you need this immediately or wish to test the functionality:
Thanks for bringing this up. |
This is now implemented in bashly 0.8.7 The relevant documentation bit was added to the Configuration / Command / flags documentation. |
Thanks for the effort put into Bashly and for making it open source.
We have a legacy app that has 'root flags'. Is there a workaround for this?
The text was updated successfully, but these errors were encountered: