Comments (11)
One more thing, by the way.
If you are just looking to create some sort of "predefined commands" for docker (with or without variable substitution in the commands), you can also consider using one of my other bash productivity tools:
- opcode - lets you define commands in an
op.conf
file, and execute withop <command> <args>
. This is designed to be a user friendly Makefile alternative. - alf - bash alias generator with "sub-alias" support. I am using it heavily to have my own docker (and git and many others) subcommands. See for example my docker related bash aliases defined in alf, which can be executed with
d
instead ofdocker
.
from bashly.
I don't understand the use case.
from bashly.
For example, I have a separate program that is being wrapped in a command by bashly and thus it has it's own documentation and execution.
The wrapper is intended to fulfill all runtime necessities, like all environment dependencies for the external command.
Let's say, I want to wrap docker
program in a script that prepares environment variables
name: console
help: Console
version: 0.1.0
commands:
- name: docker
catch_all: true
help: Docker wrapper
# docker_command.sh
docker -e MY_CUSTOM_ENV="foo" ${other_args[*]}
In this case, if I run ./console docker --help
it will run the bashly's generated help
./console docker --help
console docker - Docker wrapper
Usage:
console docker [...]
console docker --help | -h
Options:
--help, -h
Show this help
But I want to be able to mark the --help
of this command to not be processed by bashly
from bashly.
Hmm. Seems like a weird and confusing edge case.
Wouldn't a help
subcommand be better?
name: cli
help: Sample application
commands:
- name: docker
short: d
help: Run docker
catch_all: true
commands:
- name: help
help: Show docker help
from bashly.
In case of help
subcommand, I cannot run parent as an individual command.
Also wouldn't it mean that I should write wrappers for all docker
program's commands?
from bashly.
I am not 100% clear on what you are trying to do, probably.
Are you trying to create a bash script named docker
to wrap the real docker? If so, I would advise against it.
If not, and you are just trying to build a utility that sets some environment vars or does other things before delegating the entire command line to the real docker
, then I feel that the below guidelines apply:
- If someone wants
docker
help, then can just rundocker --help
- As a convenience, they can run
yourscript docker help
which will just calldocker --help
- Your help function can do whatever you need it to do - including, for example, allow
yourscript docker help build
oryourscript docker help pull
. - The syntax
yoursript docker build --help
will not be supported by your app - it is confusing anyway, since... - ... the
--help
flag is always, in any other CLI, responsible for showing the help of that CLI.
Now - despite the fact that my intuition says you should avoid overriding the *_usage
functions, a part of me sees a small chance that this could be useful, so - lets explore this further for a second.
As it happens, if a bash script contains two functions with the same name, the last one will be the one that is used. This "feature" allows you to actually "override" any *_usage
function by simply putting it in a lib
subdirectory.
Can you try it?
Run bashly add lib
to initialize a lib
subfolder.
In it, you can create a file with the same name as the usage method you want to override, and write that override function in it.
Remember that all files in lib
(even in subdirectories) are added to the script as is, so you can even put these override functions in lib/usage/*.sh
.
I am not saying this is the most elegant thing (since you will have two functions with the same name in the script), but for the sake of discussion at least - is that solving this use case?
from bashly.
The second scenario with library inclusion works, it's the way I already implemented it, but the fact that there are duplicate functions in the output is a bit confusing.
About the first scenario, on the second thought it would actually work fine too, but I'm not able to run other commands ./console docker [docker command]
besides of ./console docker help
in case of this configuration:
name: console
help: Console
version: 0.1.0
commands:
- name: docker
short: d
help: Run docker
catch_all: true
commands:
- name: help
help: Show docker help
from bashly.
Right. Yes, this wont work, since once we added a help
command, the entire script switched to command mode and is now console [command] [<catch_all>...]
.
What is the real use case? Are you trying just to set up environment variables before running docker? If so, it feels like an overkill.
If not, and you are also adding your own args or flags, like console docker build --production IMAGE
then in any case, you already have to add a console docker build
command code, so you can have something like this:
name: console
help: Console
version: 0.1.0
commands:
- name: docker
short: d
help: Run docker
commands:
- name: help
help: Show docker help
catch_all: true
- name: build
help: Build image
catch_all: true
flags:
- long: --production
short: -p
help: Build using the production Dockerfile
Note that with this setup you can run:
$ console docker help ANYTHING...
$ console docker build [--production] ANYTHING...
And delegate the ANYTHINGs
forward to docker.
This is what I would do, based on the details I understand from your statements so far.
from bashly.
Thanks a lot, I will rethink the solution on your insights.
from bashly.
Sure thing. And if you are still not happy with the result, let me know, we can see what is missing in bashly to allow it.
from bashly.
I am going to close this, but feel free to comment or open a new issue if you have new thoughts on the subject.
from bashly.
Related Issues (20)
- Support Private Flags HOT 2
- Custom libraries for `bashly add` HOT 10
- Make `bashly.yml` and `settings.yml` paths configurable HOT 1
- Command Validation misses commands named like flags HOT 2
- bashly add completions error HOT 8
- Questions about environment variables HOT 3
- Compose imported config with additional items HOT 6
- Is there any security consideration for the "bash name"? HOT 4
- Provide a third state to `strict` which omits `set -e` HOT 10
- Support for Alternate Dependencies HOT 12
- bashly about “The goal is to generate a new file and fill it with many variables” HOT 2
- Do something when a root command's flag is set HOT 8
- The `initialize` file is not loaded when using `.bash` extension
- Treat `initialize.sh` like the `before` and `after` hooks
- Automatically execute bashly generate when file change HOT 3
- Support storing variable via yaml file HOT 4
- `allowed` incompatible with `required: false` HOT 6
- Flags should not be set to their default value if not explicitly used HOT 3
- Flags must have a long form if you specify a default value HOT 3
- Whitespace not respected in here documents HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bashly.