News for hackers. Stuff that matters.

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?

( 14 comments | 4 points | on HN )
Re:What is the best language/framework to write CLIs in 2018? by stevekemp on Thursday May 03, 2018 @05:15AM (#16984451)
It 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..

Re:What is the best language/framework to write CLIs in 2018? by donatj on Wednesday May 02, 2018 @03:06AM (#16974774)
I 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.
Re:What is the best language/framework to write CLIs in 2018? by neilsimp1 on Thursday May 03, 2018 @08:03AM (#16985151)
Granted, 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 and found the library to be a pleasure to work with.
Re:What is the best language/framework to write CLIs in 2018? by jordancampbell on Wednesday May 02, 2018 @02:59AM (#16974742)
I 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.

Re:What is the best language/framework to write CLIs in 2018? by wawhal on Wednesday May 02, 2018 @04:19AM (#16975004)
Type safety is important to me. So not going for python.

Otherwise python is the go-to because of the libs.

Re:What is the best language/framework to write CLIs in 2018? by dragonwriter on Wednesday May 02, 2018 @09:22AM (#16976577)
> Type safety is important to me.

Isn't that what mypy is for?

Re:What is the best language/framework to write CLIs in 2018? by BjoernKW on Thursday May 03, 2018 @08:05AM (#16985166)
In 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.
Re:What is the best language/framework to write CLIs in 2018? by vgy7ujm on Thursday May 03, 2018 @08:30AM (#16985343)
Python can feel sluggish due to slower startup time so I would skip that and use either Perl or Go.

Definitely Perl for UNIXy stuff.

Re:What is the best language/framework to write CLIs in 2018? by vgy7ujm on Thursday May 03, 2018 @08:27AM (#16985316)
Perl or Go for sure.
Re:What is the best language/framework to write CLIs in 2018? by wawhal on Tuesday May 08, 2018 @02:30AM (#17019224)
Never 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?

Re:What is the best language/framework to write CLIs in 2018? by vgy7ujm on Tuesday May 08, 2018 @07:01AM (#17020077)
Perl has decades worth of high quality libraries to do heavy lifting. 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.

Re:What is the best language/framework to write CLIs in 2018? by vgy7ujm on Tuesday May 08, 2018 @07:03AM (#17020087)
I 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.

Re:What is the best language/framework to write CLIs in 2018? by vgy7ujm on Tuesday May 08, 2018 @07:23AM (#17020170)
For 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.
Re:What is the best language/framework to write CLIs in 2018? by wawhal on Wednesday May 09, 2018 @05:08AM (#17028416)
Nice. Thanks.