Comments (11)
This was raised in #258, implemented in #271, and available in bashly v0.8.7.
See this documentation section and the docker-like example.
Is this what you need?
Also - if you want to just have similar flags in several commands, you do not need to use import - you can use YAML anchors:
commands:
- name: upload
flags:
- &fprce
long: --force
short: -f
help: Force something
- &debug
long: --debug
short: -d
help: Debug something
- name: delete
flags:
- *force
- *debug
- long: --query
help: Other flags
from bashly.
I have added a Reusable Flags Example - in case this is the pattern you were looking for.
from bashly.
Well It is fine for me
but I think
It would be better to set common flags and ENVs in additional top bashly.yml section
named global: or common:
for sake of clarity
regards
from bashly.
I thought about it, and decided against, since the root config is the same as command config, and there is no way that both "flags" and "global_flags" will exist - its only one.
- If a command has both
flags
andcommands
- it means the flags are global, and will be available to all commands - If a command has only
commands
, each command may have its own flags - If a command has only
flags
(and maybeargs
) it is used by the command itself.
I think it works.
Generally speaking, I feel that having global flags before the command is bad form. I would recommend anyone to try and avoid using this at all, and instead, define the needed flags directly in the command(s) that need them - but, since there was some demand, I enabled this option as well.
from bashly.
Well there is already global flag --help
so I think there could be more of them
from bashly.
I am not following. You can create more global flags by using the method I outlined above.
The --debug
flag in this example is going to be "global".
And to clarify: --help
is not a global flag. It is a flag that is available on all commands, including the "root" command. It is different.
from bashly.
OK i rewrite your example from a few comments ago
common:
flags:
- force
long: --force
short: -f
help: Force something
- debug
long: --debug
short: -d
help: Debug something
commands:
- name: upload
flags:
long: --some_upload_flag
help: Other flags
- name: delete
flags:
- long: --query
help: Other flags
This way every command gets force and debug flags
$ cli upload arg --some_upload_flag --force --debug
$ cli delete arg --query --force --debug
common section is descriptive and in bashly spirit
Of course that's my 2 cents
from bashly.
Ok - this is not bad actually. So we are talking about common flags and not global flags.
It is a good idea, I need to think about it.
The primary concern I have with it, is that it adds yet another way of sharing flags or other definitions between commands. There are several already, and I am afraid of confusing users.
What else other than flags do you expect to find in the common
section?
from bashly.
After reviewing, I have decided to not implement this for the time being.
Using global flags or reusable flags can be easily achieved with one of the methods I mentioned above, and adding another configuration construct like this will complicate things (like deeply nested commands) and just add more edge cases that need to be take care of.
Nonetheless, thanks for the suggestion - I hope your use case can employ one of the methods already available.
from bashly.
Well I think there are some useful common flags that works on any commands and any level of application
for example --help --verbose --debug --version --dry-run --logging etc.
so such section as common: could be only improvement and easily understood by everyone.
In my opinion - better than native yaml solutions,
but It is of course your decision.
regards and thx for good work :)
from bashly.
You did notice that I provided another solution other than the YAML aliases right?
See this documentation section and the docker-like example.
from bashly.
Related Issues (20)
- 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
- Decide whether to use `bashly-` prefix for YAML configs HOT 6
- `bashly` completions for Bash, Fish, Zsh HOT 17
- Private commands appear in completion suggestion
- Questions about generated scripts (set -e) HOT 2
- Color escape sequences are not correctly shown in terminal HOT 8
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.