Live data from Hacker News

Diving into Go by building a CLI application

eryb.space

31–40 of 124 posts

Re: Diving into Go by building a CLI application

#32
post #10

Since everyone else is throwing out recommendations I personally think https://github.com/spf13/cobra is the best CLI templating system, especially because of how well it pairs with https://github.com/spf13/viper . Large projects like Hugo and Kubernetes have used Cobra to build their CLI tools, and it's fairly light as well even if you need simpler usage. We use it at my workplace simply for wrapping our microservic…

[deleted]

Re: Diving into Go by building a CLI application

#35
post #28
post #21

Go is a particularly good language for CLI's I have found. At least compared to Java/C#/Python. It's reasonably fast, compiles down to a simple to distribute binary, and the language is forgiving enough that you can do exploratory programming in it. Go-routines make it especially easy to deal with network calls in it as well. For anything that needs absolute performance though look elsewhere, but even then Go might b…

CLIs are sorta my ideal use-case for Go. Goroutines are so error-prone to control since you don't have many options for abstraction, so it's relatively difficult to build long-running highly-stable programs... But CLIs don't usually need that. They can be ctrl-C'd if they go off the rails, and any dangling goroutines just die when the process dies. The simple distribution, fast startup, simple type system, and yolo-c…

As the typical SysAdmin who likes to automate stuff, I have to agree. I am not experienced enough to talk about language designs. But I can say, that writing some small CLI application and deploying it onto some server is way less work with go. Simply because you can crosscompile the application and generate a standalone binary.

Everytime I deploy some Python3.7 Flask Application on RHEL7 I start to scream.

You were talking about long running applications and broken goroutines: What is the best alternative? I liked to stumble around in Elixir but I feel bad about deploying some application probably nobody at my office will ever be able to 'fix/update'. Python feels too "sluggish". Since I am no Python Pro I have often the feeling, that I am doing something wrong because the language doesn't show any borders.

Re: Diving into Go by building a CLI application

#36

Is it possible to display images in terminal? Terminal is simultaneously powerful and painful tool. I know a guy that refuses to use anything but CLI and suffers a lot. But most basic apps can be written it in like those BIOS menus from a 2005 dell computer.

You may be unfamiliar with the history of terminals, in which case this explanation is for you.

What you might think of as the terminal is really a terminal emulator. A terminal was a device with a screen and keyboard (early terminals like the Teletype were printers with keyboards, or typewriters). Most could only display text. Up until the late 1970s or so, computers were invariably large and most did not come with their own built-in, memory-mapped display hardware. To access them, you had to use one of these terminals which connected usually via a serial cable.

Because Unix was designed to work with these terminals as the user's means of interaction, terminal emulators which spoke the same protocol as the actual terminals became common. When Unix got graphical displays, terminal emulators were based on them so that old, text-based Unix programs could continue to be used in the graphical environment.

Some graphical protocols for terminals emerged. xterm supports three such protocols: Tektronix 4014, DEC Sixel, and DEC ReGIS. Sixel can be used on xterm to transmit color images. However, Sixel support is usually not compiled in by default.

Perhaps the most sophisticated graphical protocol for terminals to emerge into common use was X itself. Yes, vendors used to sell X terminals that were basically bare-bones computers without any local storage, just a network connection that allowed it to present a windowed display from a remote machine.

Re: Diving into Go by building a CLI application

#37
post #21

Go is a particularly good language for CLI's I have found. At least compared to Java/C#/Python. It's reasonably fast, compiles down to a simple to distribute binary, and the language is forgiving enough that you can do exploratory programming in it. Go-routines make it especially easy to deal with network calls in it as well. For anything that needs absolute performance though look elsewhere, but even then Go might b…

> [Go] is forgiving enough that you can do exploratory programming in it.

I agree with most of your post, but I’m not sure I would describe Go as “forgiving”. In fact, it’s well known for being strict. For example, exploratory programming would be significantly easier if the Go compiler could (optionally) ignore unused variables and unreachable code.

I’ve also found exploratory programming in Go is hindered by needing to frequently cast between different integer types. Maybe I’m doing something wrong, but my Go code is often littered with casts between different integer sizes and signedness. It’s much easier with Python’s arbitrary-precision integers.

Re: Diving into Go by building a CLI application

#38
post #37
post #21

Go is a particularly good language for CLI's I have found. At least compared to Java/C#/Python. It's reasonably fast, compiles down to a simple to distribute binary, and the language is forgiving enough that you can do exploratory programming in it. Go-routines make it especially easy to deal with network calls in it as well. For anything that needs absolute performance though look elsewhere, but even then Go might b…

> [Go] is forgiving enough that you can do exploratory programming in it. I agree with most of your post, but I’m not sure I would describe Go as “forgiving”. In fact, it’s well known for being strict. For example, exploratory programming would be significantly easier if the Go compiler could (optionally) ignore unused variables and unreachable code. I’ve also found exploratory programming in Go is hindered by needin…

What I mean is that while the compiler is strict its fairly easy to throw something together that mostly works. The large standard library really helps there. It's certainly not as easy as in Python though.

Re: Diving into Go by building a CLI application

#39
post #10

Since everyone else is throwing out recommendations I personally think https://github.com/spf13/cobra is the best CLI templating system, especially because of how well it pairs with https://github.com/spf13/viper . Large projects like Hugo and Kubernetes have used Cobra to build their CLI tools, and it's fairly light as well even if you need simpler usage. We use it at my workplace simply for wrapping our microservic…

Great stuff! Does anything like Cobra exist for Java?

Same question, but for C++?

I’ve struggled to find a well-supported command-line argument parser that supports subcommands.

Re: Diving into Go by building a CLI application

#40
post #21

Go is a particularly good language for CLI's I have found. At least compared to Java/C#/Python. It's reasonably fast, compiles down to a simple to distribute binary, and the language is forgiving enough that you can do exploratory programming in it. Go-routines make it especially easy to deal with network calls in it as well. For anything that needs absolute performance though look elsewhere, but even then Go might b…

I've found Rust to be more interesting for CLIs than go. Especially when using https://clap.rs
Post reply on HN