[Experiment] A way to put configuration in the same file as its command #151
Replies: 3 comments 1 reply
-
Interesting point. I also asked myself the same question (although not in bashly's context): is it better to have one file contain multiple information types, or have a separate file for each data structure/concept. To me, the arguments for each side are usually almost equally weighted, which automatically gives priority to the simple approach of having each concept in its own file. Now, bashly needs However, there might be a way to alleviate some of the issues, and perhaps even satisfy this feature. Not sure yet it will work or be 100% straight forward to implement, but here goes.
In other words, imagine these two files: # bashly.yml
name: cli
commands:
- load: src/download
- load: src/upload # either `src/download.yml` or front matter in `src/download_command.sh`
name: download
short: d
help: Download a file
args:
- ...
- ... now, the only thing left to implement is the removal of front matter from the shell scripts. What do you think? Worth exploring further? |
Beta Was this translation helpful? Give feedback.
-
Yeah, well I thought my gem could help, but I doubt it. It was meant to "extend" YAMLs, not "include" snippets. But still - I think that having a special, YAML-compatible command (like As for the decision to load other YAMLs or front matter - I am thinking about supporting both use cases, so people can decide which to use. For example, some users might like to continue using YAML, but would prefer to separate it to multiple YAML files - this is why I included the full path in my I will kick off a PR, see where it goes. |
Beta Was this translation helpful? Give feedback.
-
The PR is ready: #154 |
Beta Was this translation helpful? Give feedback.
-
I haven't decided if this is a good idea or not, but I've been trying out a way to put configuration for a command in that command's file, rather than centralizing everything into
bashly.yml
. The advantage of this approach is that all of the information about the command, its flags, etc. is stored in the file, where it's much easier to see than switching between files (particularly, I got confused a couple of times and was looking at the wrong command in the config file, which is much harder to do when you can only see one config at a time). The disadvantage, of course, is that Bashly doesn't actually support this.I've implemented this with the simplest approach possible; I've defined a special kind of comment (
#:
) which should contain the YAML; these comments all get extracted and concatenated together to produce thebashly.yml
file for ingestion. It looks something like this:initialize.sh
download_command.sh
Presumably I ought to be doing some sort of front-matter extraction and parsing so that I can point syntax errors at individual files and so on, but in practice I just use the following script:
As it stands this only works properly if you have exactly one level of subcommands, and also doesn't interact with command groups very well (since the commands end up in filesystem—usually alphabetical—order, and Bashly expects them to be clumped together with the
group
key on only the first item in the group; so there's mostly no way to do that under this system).Not sure if this is worth pursuing any further but I thought it might at least provoke an interesting discussion.
Beta Was this translation helpful? Give feedback.
All reactions