Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GO C-Style Console Application

I created a Go CLI app with the cobra framework via the cobra add command. After building it with go build it works totally fine if I'm in the repository in the windows cmd. If I click on the .exe I get the following message on a terminal:

This is a command line tool.

You need to open cmd.exe and run it from there.

This is not suitable for my case. I'd like to have a console applocation like in C or C++ which opens directly and you can type in commands there. Do you have any suggestions how I could realize this while using cobra?

Thank you a lot in advance.

like image 299
alexfwulf Avatar asked Dec 30 '25 23:12

alexfwulf


1 Answers

This is done on purpose as no arguments will be provided to the command when started through explorer.exe, as the main purpose of using cobra is for parsing arguments and stuff.

To disable this feature.

Add this line in your init()

func init(){
  cobra.MousetrapHelpText = ""
}

This let's your program run, and it exits immediately, to see if it's working fine. Use time.Sleep(), so that you can see the output.

like image 171
nilsocket Avatar answered Jan 01 '26 14:01

nilsocket



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!