7 ms·
Bashly – Create beautiful bash scripts from simple YAML configuration
- UncleOxidant 5y agoAnd now you have two problems.
- iamjackg 5y agoHah! I have to admit that I spent quite some time thinking about whether I wanted to use this or switch to a "real" language. For all its shortcomings, I find that shell scripting is still the easiest way to put together a tool that needs to interact with a lot of other commands, no matter how large it ends up being. I love Python to death, but using `subprocess` for everything is the opposite of my idea of a good time.
- Spivak 5y agoThe syntax for basically every "real" programming language is amazingly unurgonomic at interoperating with the outside world and moving/transforming data which is why shells are still super popular. You would think there would be more effort supporting this since it's so tedious to have a billion libraries that are just wrappers around http apis and external utility calls.
- dolni 5y ago"Real" programming languages are leagues ahead of shell scripting languages in terms of transforming and moving data around. Most shell utilities are focused on text processing or are thin wrappers around system calls. If you're using something like python's `subprocess` module to get at these, you're doing it wrong. Interactivity is where shells have an advantage. Their syntax lends itself well to that. It's also why the syntax sucks for regular programming.
- ilyash 5y agoBefore there are 10 people with "there is a library for that in Python" (because they are not and can not be ergonomic enough): Next Generation Shell is a "real" programming language. It also has syntax for calling external programs. It handles exit codes properly. It has facility for constructing command line arguments. Project - https://github.com/ngs-lang/ngs https://github.com/ngs-lang/ngs Motivation related to the above - https://ilya-sher.org/2017/10/10/why-i-have-no-favorite-programming-language/ https://ilya-sher.org/2017/10/10/why-i-have-no-favorite-prog... edit: ah, yes, NGS also supports command line arguments automatic parsing when main() is called; augmenting this facility would be the sane way to solve the problem.
- chews 5y agoAll we need a C++ build step to really achieve footgun criticality.
- layer8 5y agoThat will be fixed by introducing Yamly.
- dharmab 5y agoWhat are some concrete use cases for this?
- iamjackg 5y agoIn my case, I used it to build an all-in-one tool for a local dev environment. It wraps all kinds of operations for starting/stopping things, extracting and modifying data, etc. while providing some useful tips when things go wrong. At its core it's just interacting with existing software like docker-compose, git, and some internal tools, which I find is still much, much easier to do with shell scripting than "proper" languages.
- kqr 5y agoHave you tried Perl?
- iamjackg 5y agoI have, and I quite like it! That doesn't seem to be the way most people feel about it though. I need to build things that pass the bus audit: other people also have to understand them and work on them and, for better or for worse, Bash is a very popular lowest common denominator for many devs.
- tkiolp4 5y agoI usually use Ansible for that. Check it out!
- iamjackg 5y agoAnsible is awesome, but would largely be overkill for something like this. I'm not doing much more than ensuring a few things are in place, merging a couple files, and then running docker-compose up/down, or exec-ing into running containers to run commands. I certainly wouldn't want people to have to run an entire playbook just to do all this: it's slow, requires even more setup, and is not really well suited for quick CLI-like use.
- 5y ago
- philipov 5y agoI really dislike the animated gif. Let me stare at what it says as long as I want/need to. Not allowing the user to move at their own pace is bad UX.
- tacLog 5y agoI really liked it because it drew my attention when I might have skipped over a block of text. However, I wanted to go back and see what was earlier or view the source input and output. So I would also like it if the contents of the gif was printed out below for easier access.
- dannyben 5y agoWell - there is a documentation site if you want to stare... the animated gif is for people who want a "drive-by" look at what it does.
- philipov 5y agoIt is both too fast and too slow. It's too fast to read it, and it's too slow for a drive-by look. Just put the document on the page like a normal person.
- petethepig 5y agoPretty landing page, but I'm going to be honest, it took me a while to understand what this project does and the gif did not help unfortunately.
- city41 5y agoThe front page of its website does a better job explaining: https://bashly.dannyb.co/ https://bashly.dannyb.co/
- esoterae 5y agoSooo.. it's a yaml-based bash DSL that manually cross-compiles back to .. bash? It's probably clever, sure, but it seems like this would wind up more declarative than imperative?
- dannyben 5y agoNo. No DSL. 1. Define your commands + flags + args in YAML (`bashly init` creates this YAML). 2. Bashly generates the standalone script and empty "placeholder" scripts for your actual bash code (`bashly generate`). 3. You plug in your bash code. 4. Bashly merges it all back to the same single final script (`bashly generate`). 5. Rinse and repeat.
- verdverm 5y agoThe yaml schema is in essence a DSL. It has required terms that have a specific meaning, in this case specific to CLI UX. What happens when I get to 5 and want to change an arg for cdm/foo? Does step 3 need to be repeated in its entirety?
- dannyben 5y agoNo need to repeat step 3. Code for each command (in case you want a bash script with subcommands), is placed in `src/<command_name>_command.sh`. Running `bashly generate` will always read it and re-merge it. I think this is a good minimal example: https://github.com/DannyBen/bashly/tree/master/examples/minimal#minimal-example https://github.com/DannyBen/bashly/tree/master/examples/mini...
- LambdaComplex 5y ago1. Am I the only one who gets annoyed by the abundance of software being described as "beautiful" (or some other vague, subjective term)? And, honestly, Bash is probably the least "beautiful" "programming language" I can think of. 2. If you need this level of complexity, I feel like you should be reaching for Python or Go or something else that definitely isn't Bash
- iamjackg 5y agoFor 1, I do agree that the term is overused, but in this case it's not really about the beauty of the code itself: it's about the fact that the final generated script acts in a predictable way and prints information and help messages in a format that people are already familiar with. You don't have to write your own usage message: it does it for you, and it looks the way I would expect a usage message to look. I also see argument 2 a lot, and I've already addressed this in other comments, but sometimes you really just need to call a couple of commands while prepping some env vars or config files for convenience. In those cases, reaching for Python or Go ends up being a lot of boilerplate for very little advantage, especially when you want to pass control over to other applications once you're done setting things up.
- layer8 5y agoRe 1, the problem is that "beautiful" doesn’t tell you anything useful, other than (being uncharitable) the author having succumbed to tech marketing hype speech.
- stuff4ben 5y agoAnd then I have to learn Python or Go. Bash is ubiquitous and for the things I'm doing scripting for, something like this would be a pretty good use-case. Usually my scripts start out simple, but then become unwieldy monsters over time. I could use something like Bashly to refactor my monster Bash script to something more manageable.
- clipradiowallet 5y ago> 1. Am I the only one who gets annoyed by the... No you aren't. This irritates me also. Bash is about as beautiful as perl. > 2. If you need this level of complexity, I feel like you should be reaching for Python or Go or something else that definitely isn't Bash This is true. Otherwise you risk [in bash] creating something very difficult to maintain for future contributors. The lengths people will go to avoid "programming" can be quite staggering.
- iamjackg 5y agoSince the landing page is not the clearest, you can think of this as an argparse equivalent for Bash. You provide a YAML file listing commands, subcommands, arguments, and flags, and it automatically generates a Bash script that can parse and validate them, provide help messages, and run your code for each command. It also lets you keep the actual code for each command and subcommand in separate files, which are merged together into one distributable Bash script at generation time. It's basically a templating system to auto-generate argument parsing so you don't have to solve that again or deal with things like optparse.
- mxuribe 5y agoHave you considered submitting your 3 sentences to the project?? Because in the mere moments that it took me to read your 3 sentences i got the gist of what this does instantly! Thanks for providing this, and please do consider submitting this so that others can learn from you and benefit the creator of their app.!
- deleted 5y ago[deleted]
- dj_gitmo 5y agoI appreciate that this exists. Writing the CLI is the most annoying parts starting a new bash script.
- markstos 5y agoI'll stick with `sub`: https://github.com/qrush/sub https://github.com/qrush/sub
- dolni 5y agoThe mistake here is assuming that every shell script needs complex argument parsing, subcommand support, and a verbose usage message. I would even go so far as to say they're _rarely_ needed.
- verdverm 5y agoI've used the following to get 80% of the way there > ${1:?help message} Using python more these days however
- verdverm 5y agoShameless plug, I wrote https://github.com/hofstadter-io/hof https://github.com/hofstadter-io/hof as a generalized tool for what this does, i.e. generate boilerplate from a DSL. https://github.com/hofstadter-io/hofmod-cli https://github.com/hofstadter-io/hofmod-cli is the same idea for generating Go CLI boilerplate. hof uses CUE instead of Yaml, can output to any and multiple languages, and uses diff3 so you can work in both the output and the design at the same time.
- simonw 5y agoThe animated console demo in the README is actually an animated SVG file: https://github.com/DannyBen/bashly/blob/master/demo/cast.svg https://github.com/DannyBen/bashly/blob/master/demo/cast.svg Anyone know what tool is used to create that?
- dannyben 5y agoYou can see the autohotkey script in the same folder: https://github.com/DannyBen/bashly/blob/master/demo/demo-maker.ahk https://github.com/DannyBen/bashly/blob/master/demo/demo-mak... It was created with asciinema and svg-term-cli
- simonw 5y agoI'm a tiny bit disappointed to see that the tool itself is written in Ruby - writing it in Bash (with a command-line interface that was generated by itself) would be deeply nerdily pleasing to me. Totally understand why you would write this in Ruby instead though!
- dannyben 5y agoHeh. Yeah, this would be a satisfying nerdy accomplishment. Note there is a docker image if you want to use it without having Ruby.
- thunderbong 5y agoIMHO, I don't think most people commenting here are getting it. As an example, here's a bash alias generator, alf [0], which itself is a bash script, created using this. The bash script for alf is note really small [1]. Additionally, the output is extremely readable unlike most other bash scripts I myself have written! Really amazing piece of software! Kudos. [0]: https://github.com/DannyBen/alf https://github.com/DannyBen/alf [1]: https://raw.githubusercontent.com/DannyBen/alf/master/alf https://raw.githubusercontent.com/DannyBen/alf/master/alf
- jdmg94 5y agoIdk but this doesn’t sound like a good idea
- davidpfarrell 5y agoAlthough bash-specific, Bashly falls into the "Task Runner" category. As such, I would like to chime in with my entry: Run : https://github.com/TekWizely/run https://github.com/TekWizely/run It has its own DSL for describing tasks, along with help strings and argument descriptors, and can manages generating help screens, parsing args and invoking tasks (sub-commands). Each task can be written in its own language, one task could be Bash, one could be zsh, one could be python, etc. If you're in the market for a flexible task runner, I hope you'll give it a chance.