4 ms·
What is the best language/framework to write CLIs in 2018?
Hello HN,
I have an idea for a CLI and want to start writing it soon. I want a robust language/framework that is meant for writing CLIs. I have used Golang/Cobra before and I have done minor things using C++.
I also want this to be a learning experience. So I will be starting with the language/framework from absolute scratch.
So the secondary question behind this Ask HN is, which CLI framework should you know in 2018?
- stevekemp 8y agoIt depends largely on what you're doing, and where it will be running. If you're writing something that takes a bunch of flags, then parses text, I'd use perl. If you're using somethign that must be easily installed on 100+ hosts then perhaps a binary compiled from go - because that's easy to install. For frameworks? That's probably secondary to the actual core of your application. If you're writing a complex UI with (n)curses then that's more interesting and complex than calling getopt a few times..
- neilsimp1 8y agoGranted, I've only ever written CLI apps using this and nothing else, but I've written a few smaller CLI apps in C# using https://github.com/commandlineparser/commandline https://github.com/commandlineparser/commandline and found the library to be a pleasure to work with.
- BjoernKW 8y agoIn terms of portability and installed base Python or Perl probably are the best choices. They come installed with most UNIX, BSD or UNIX-like operating systems such as Linux.
- vgy7ujm 8y agoPython can feel sluggish due to slower startup time so I would skip that and use either Perl or Go. Definitely Perl for UNIXy stuff.
- vgy7ujm 8y agoPerl or Go for sure.
- wawhal 8y agoNever used Perl. Would love to learn it. Just went through the overview. Looks like a high-level scripting language which inherits a lot from C. After all the research, I am still highly inclined towards Golang. Since you said "Perl or Go", you seem to have used Golang. How does Perl compare with it?
- vgy7ujm 8y agoPerl has decades worth of high quality libraries to do heavy lifting. https://metacpan.org https://metacpan.org You can get away with easy scripting for creating significant programs. UNIX commandline and Perl is a match made in heaven. Using Golang will demand significantly more effort when doing more complex stuff but will give you concurrency, easier deploys/multi-platform support and better performance if doing CPU intensive stuff.
- vgy7ujm 8y agoI use Go for what I previously maybe used C for. Thanks to the quick compile time and good tooling Go almost feels like a scripting language when developing but especially for UNIXy stuff it can't replace Perl for me.
- vgy7ujm 8y agoFor learning I would highly recommend the following books: Beginning Perl by Ovid. Modern Perl by chromatic. There are a lot of other good Perl books but some of them are getting old and it is better to already know a bit before reading so one can separate good from dated etc.
- wawhal 8y agoNice. Thanks.
- jordancampbell 8y agoI write all my CLIs in Python. I find that I always need various random things to work together and have always found Python to be the most robust at this. Plus it has pretty much anything you'd need already implemented.
- wawhal 8y agoType safety is important to me. So not going for python. Otherwise python is the go-to because of the libs.
- dragonwriter 8y ago> Type safety is important to me. Isn't that what mypy is for?
- donatj 8y agoI know you’ve used Go, but I personally think it’s unbeatable mostly because it’s statically compiled binaries make them super portable. Compile once and you can distribute a single binary file per platform.