How to set up a binary name in Go without changing the path

I am developing a small tool with Go. And recently, I noticed that the tool needs to be called from a shell script because it uses a shell function.

Suppose my tool is called atool . So go build generates a binary atool , and my tool has a Go structure like github.com/myaccount/atool . Now I want to build atool-cli binary with go build and call it from the atool script atool . How can i achieve this?

The only way that comes to my mind is to change the go structure like github.com/myaccuont/atool-cli . But I do not want to do this, because the already announced one, as well as the way, seems a little ridiculous.

+6
source share
2 answers

Just to make my comment "official":

 go build -o atool-cli github.com/you/atool 
+9
source

One package path structures itself as a library and provides core packages to put their main entry points in subdirectories.

You can have a main package in github.com/myaccount/atool/atool-cli that imports github.com/myaccount/atool and implements func main() . Some packages with several commands even have a directory /cmd/ with several cli tools that can be created (see camlistore for an example)

+7
source

Source: https://habr.com/ru/post/973252/


All Articles