Comments (6)
Aloha. I think this was mentioned and discussed somewhere, but I don't remember where or what was the conclusion.
Let me play with it a little, see what can be done.
Thanks for the detailed ticket in the meantime.
from bashly.
Whoa, I've never even heard of GitHub "Discussions" 🤯 Or I would have gone there first. I see the tab at the top of the repo now, awesome, will definitely start there next time unless I'm actually raising an issue. Anywho, thanks again!
from bashly.
Found where it was discussed: #273
from bashly.
So, here are some pointers. This is a long one, so strap in.
YAML must be a valid YAML
As you discuvered, the below is invalid:
flags:
import: src/common_flags.yml
- long: --debug
There are two validations that take place:
- The YAML itself must be valid before anything else (and the above is not valid YAML).
- After the YAML is valid, it is loaded to Bashly, which can validate its schema.
Pre-processing with Kojo
The above syntax requires processing the YAML file as a text file (before using YAML.load_file
). This is outside the scope of Bashly.
As it happens, I have tool for that, named Kojo. With it you can pre-process the bashly.yml file as follows:
# bashly_src.yml
name: cli
flags:
@import common_flags
- long: --debug
# common_flags.yml
- long: --json
- long: --quiet
$ kojo file bashly_src.yml
name: cli
flags:
- long: --json
- long: --quiet
- long: --debug
If you choose this solution, your "build" step will be something like this:
$ kojo file src/bashly_src.yml --save src/bashly.yml && bashly generate
Importing individual flags
You can still use bashly's native import
in a merged context. You just need to merge the individual elements (flags):
# bashly.yml
name: cli
flags:
- import: src/flag_quiet.yml
- import: src/flag_json.yml
- long: --debug
# src/flag_json.yml
long: --json
# src/flag_quiet.yml
long: --quiet
Global flags
If you have flags that appear in all subcommands, you can put them on the root command:
# bashly.yml
name: cli
flags:
- long: --debug
commands:
- name: download
flags:
- long: --json
$ ./cli --debug download --json
args:
- ${args[--debug]} = 1
- ${args[--json]} = 1
Anchors
As you mentioned, using YAML anchors is another way of solving this issue (example). Personally, I find it the most straight forward.
With all these options, I do not feel there is a need to complicate it further.
Don't forget that the bashly.yml is just the skeleton configuration - if it becomes so large that you need to consider alternatives that are not presented here, I suspect the problem lies elsewhere.
Also - I consider the import
feature, more of a leaf in the implementation, rather than a branch, which means that expanding it further must have an epic reasoning, and a very simple implementation.
I hope one of these options points you in the right direction, and am still open to discuss further.
from bashly.
Thanks @DannyBen for that in-depth and clear response, it is very helpful to me. 🤙🏻 Consider this question answered! (I couldn't figure out how to add the question
label myself btw, or I would have chosen that over enhancement
.)
As I am in the very beginning of my CLI project, anchors will probably be entirely sufficient, and I do like the explicitness of that technique. I'm definitely bookmarking your kojo
project though, that looks like an awesome utility. 👏🏻
from bashly.
Sure thing Daniel, glad I could help.
Questions are usually more suited for the Discussions section, but I might add a Question issue template.
If you are having any more issues or questions that are not easily answered in the docs, do not hesitate to open an issue or a discussion. Bashly should be easy to pick up, if it isn't - its a bug.
from bashly.
Related Issues (20)
- Add support for recursive --help HOT 6
- Build multi-arch docker HOT 2
- Default argument is not validated HOT 6
- Flag arguments with a single hyphen prefix are not working HOT 1
- bash completions can't work properly when the position args used 'allowed:' HOT 3
- Repeatable args don't escape quotation marks HOT 12
- Add option to disable splitting of flags with value for catch_all arguments HOT 9
- Lifecycle for temporary directories HOT 1
- Heredoc indentation issue in bashly generated functions. HOT 9
- The Flag value is detected as an Argument HOT 2
- Showing an additional usage line for forced commands HOT 3
- Is it possible to have no command and take arguments from user ? HOT 3
- Shellcheck failure on repeatable argument with allowed values HOT 3
- Default command is not triggered when only flags are provided HOT 1
- using bashly without ruby or docker HOT 3
- Bashly generated script fails shellcheck rule SC2059 HOT 11
- Allow semi-private commands HOT 5
- THIS_SCRIPT variable HOT 4
- Bug in ini library HOT 10
- eval in .zshrc triggers initialise.sh unexpectedly – Is this intended behavior? HOT 5
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.