Is importing one main package in another main package supported?

210 views
Skip to first unread message

Mitar

unread,
Dec 21, 2021, 1:14:59 PM12/21/21
to golan...@googlegroups.com
Hi!

I am trying to make a CLI tool which would have sub-commands and some
of them would call into other existing CLI tools (written in Go). The
issue is that those other commands sometimes have CLI parsing code as
part of the main package (e.g., example.com/cmd/example) and the hook
to call into the main (passing a list of arguments) is also in the
main package. I do not want to use a subprocess because that would
mean that a user would have to install those other CLI tools, too.

I understand why it is not reasonable to import main packages into
non-main packages, but my understanding is that importing a main
package into another main package should work, at least according to
[1]. But I cannot get it to work.

So is [1] wrong or has that changed since then?

Is there some other way to get `go install`ed tool to define a
dependency on another `go install`ed tool so that both are installed
as CLI tools?


Mitar

[1] https://groups.google.com/g/golang-nuts/c/frh9zQPEjUk/m/9tnVPAegDgAJ

--
http://mitar.tnode.com/
https://twitter.com/mitar_m

Ian Lance Taylor

unread,
Dec 21, 2021, 1:31:49 PM12/21/21
to Mitar, golan...@googlegroups.com
Support for importing a main package was dropped from the go tool as
part of https://golang.org/issue/4210.

Ian

Mitar

unread,
Dec 22, 2021, 9:02:11 AM12/22/21
to Ian Lance Taylor, golan...@googlegroups.com
Hi!

On Tue, Dec 21, 2021 at 7:31 PM Ian Lance Taylor <ia...@golang.org> wrote:
> Support for importing a main package was dropped from the go tool as
> part of https://golang.org/issue/4210.

I see. Thanks. The issue seems to be resolved in 2015, but the mailing
list post I referenced [1] is from December 2016. So I can assume the
post is simply false?


Mitar

Ian Lance Taylor

unread,
Dec 22, 2021, 1:32:21 PM12/22/21
to Mitar, golan...@googlegroups.com
On Wed, Dec 22, 2021 at 6:01 AM Mitar <mmi...@gmail.com> wrote:
>
> On Tue, Dec 21, 2021 at 7:31 PM Ian Lance Taylor <ia...@golang.org> wrote:
> > Support for importing a main package was dropped from the go tool as
> > part of https://golang.org/issue/4210.
>
> I see. Thanks. The issue seems to be resolved in 2015, but the mailing
> list post I referenced [1] is from December 2016. So I can assume the
> post is simply false?

It's certainly possible that the post was mistaken or relying on
outdated information, yes.

Ian
Reply all
Reply to author
Forward
0 new messages