go install github.com/dmacvicar/terraform-provider-libvirt#latest - shows error - go

I am trying to Provision VMs on KVM with Terraform.
one of the steps in installations is to download and install the provider buy the command:
go install github.com/dmacvicar/terraform-provider-libvirt#latest
but it errors:
The go.mod file for the module providing named packages contains one or
more replace directives. It must not contain directives that would cause it to be interpreted differently than if it were the main module.
I didn't find a solution, is someone has faced it?
thank you

As JimB notice in comments:
If there are replace or exclude directives in the module, the correct
installation method is to clone the source and install it,
git clone github.com/dmacvicar/terraform-provider-libvirt
cd terraform-provider-libvirt
go install

Related

Can 'go install' be made to work for executables with different names from the git repo?

Go has a nice feature where you can go install <x> and it will download, build and install a binary.
For example, on my local windows PC, go install github.com/goreleaser/goreleaser will find the latest release for goreleaser, download, build and install it to my local binaries path.
I am working on a project where we would like to enable go install, but encounter a problem if the github repo name does not match the executable name. The GitHub CLI itself runs into the exact same problem:
Example:
go install github.com/cli/cli#latest
go: downloading github.com/cli/cli v1.14.0
go: github.com/cli/cli#latest: module github.com/cli/cli#latest found (v1.14.0), but does not contain package github.com/cli/cli
Is there a way to resolve this?
Update: I worked out that I could directly reference the package via it's sub directory. In my particular instance this works: go install github.com/OctopusDeploy/cli/cmd/octopus#latest
This is a bit unpleasant, but works correctly. It doesn't work for the github CLI because their go.mod has a replace directive in it :-(
Question: Can this be made nicer? Is there a way to put some sort of alias or configuration file so that go install github.com/OctopusDeploy/cli#latest can be used instead of go install github.com/OctopusDeploy/cli/cmd/octopus#latest ?
Can this be made nicer? Is there a way to put some sort of alias or configuration file so that go install github.com/OctopusDeploy/cli#latest can be used instead of go install github.com/OctopusDeploy/cli/cmd/octopus#latest ?
No. Dead simple.

go install #latest found but does not contain package

I'm trying to install my package using go install but I get this error message when running the command go install github.com/JoaoDanielRufino/gcloc/cmd/gcloc#latest:
go install: github.com/JoaoDanielRufino/gcloc/cmd/gcloc#latest: module github.com/JoaoDanielRufino/gcloc#latest found (v1.0.0), but does not contain package github.com/JoaoDanielRufino/gcloc/cmd/gcloc
I want the executable name to be gcloc.
Here is the current source code: https://github.com/JoaoDanielRufino/gcloc
Note: I've already tried go clean -modcache but it didn't work
As the main function of this package isn't on its root, you should pass the directory of the main package on your command.
So, your command will be:
go install -v github.com/JoaoDanielRufino/gcloc/cmd#latest
I came across a similar issue when I was trying to use go install to install the cloudflare/cf-terraforming tool on my machine. The documentation for this tool is not clear on the installation and I had to dig around to get this to work
Basically #Jictyvoo answer above sums it up, if the path is pointing to anything other than directory where the main.go file is sitting I got the error
Command: go install github.com/cloudflare/cf-terraforming#latest v0.8.0#latest
go: github.com/cloudflare/cf-terraforming#latest: module
github.com/cloudflare/cf-terraforming#latest found (v0.8.0), but does not
contain package github.com/cloudflare/cf-terraforming
when I switched to the below it worked fine for me:
Command: go install -v github.com/cloudflare/cf-terraforming/cmd/cf-terraforming#latest
This worked for me after checking the repo and realising that the main.go file was sitting in the cmd/cf-terraforming subdirectory

Difficulty installing go buffalo using go mod on windows

I am very new to golang. I am trying to work with the gomod. Trying to explore the go buffalo framework. But finding a bit of difficulty in installing that.
What I have done:
I saw that go get is nomore supported for buffalo and so switched to go modules.
Created a module by go mod init github.com/webbuffalotest
Fetched go get -v github.com/gobuffalo/buffalo (on the same directory where I have go.mod file)
Fetched go get -v github.com/mattn/go-sqlite3 (on the same directory where I have go.mod file)
go install github.com/gobuffalo/buffalo
I was expecting a buffalo.exe inside %GOPATH%/bin so that I can add it to my path but didn't find one.
My question is what's wrong? Is the exe not installed or it's somewhere else because of go mod. Any help will be highly appreciated.
I am using windows 10. I am not willing to install package managers as scoop or choco to install buffalo. Thanks for your patience :)
Edited:
Also tried setting set GO111MODULE=on but of no use.
Solved:
My bad, I should have used go install github.com/gobuffalo/buffalo/buffalo instead of go install github.com/gobuffalo/buffalo
github.com/gobuffalo/buffalo is a library; the corresponding binary is (aptly-named) github.com/gobuffalo/buffalo/buffalo.
The go install command you ran should have warned you about that, but didn't because go install used to also be used to cache compiled libraries (it no longer does that in module mode).
I've filed https://golang.org/issue/46912 to add a diagnostic.

How can I install a specific version of golint for use globally?

I'm trying to create a docker image for use in a build pipeline that has various tools pre-installed for building and testing go projects. One tool we need is golint but I'm struggling to see how to install a specific version of it. The reason I want to lock down the version is to avoid accidental / unwanted / unintended breakages at a later date.
For a start, looking here the versions are not exactly in an easy-to-type format.
Also when I try to use the following command
go get -u golang.org/x/lint/golint#v0.0.0-20181217174547-8f45f776aaf1
I get an error
go: cannot use path#version syntax in GOPATH mode
Googling has so far yielded very few relevant results...
Is what I'm trying to do possible? Many thanks!
You need to be in go module mode to get code of a specific version, since in addition to downloading the code, the version is recorded in the go module file.
The easiest way to do this would be to create an empty directory, run go mod init, which will create a go.mod file.
Then, you can run go get golang.org/x/lint/golint#v0.0.0-20181217174547-8f45f776aaf1, which will add golint at that version to your go.mod file. You can then run go install golang.org/x/lint/golint from within that directory, which will install golint at the version specified into your $GOBIN directory (which defaults to $GOPATH/bin).

PHPDocumentor - Graphviz 'dot' command not found

I am trying to get PHPDocumentor running on a local XAMPP installation.
Sadly I having a hard time doing it using package managers.
Some basic questions about package managers first:
How do I know where to install a package? For example: I installed PHPDocumentor using Composer. I go to my C:\xampp\htdocs\ and run a command:
composer require "phpdocumentor/phpdocumentor:2.*"
This installs phpdocumentor in a " vendor" folder in xampp\htdocs\
Is this the correct path to install all these packages or is there a default dir to install this?
If I want to uninstall the packages, do I simply delete the "vendor" dir?
After the installation I ran PHPdocumentor and got an error:
Unable to find the dot command of the GraphViz package. Is GraphViz
correctly installed and present in your path?
To resolve this, I tried the following:
Installed the package graph/graphviz while my pointer was in the htdocs-folder and pointed a path to the folders:
C:\xampp\htdocs\vendor\graph\graphviz
...graph\graphviz\src
...graph\graphviz\tests
None of the above solved the problem.
According to this link I have to add the \graphiz\bin directory to path, but there is no "bin" dir?
Can anyone help me out with this?
Best regards,
Abayob
Unable to find the dot command of the GraphViz package. Is GraphViz correctly installed and present in your path?
The steps to resolve this error are:
download zip from https://graphviz.gitlab.io/_pages/Download/Download_windows.html
extract to c:\some\where\graphviz
add c:\some\where\graphviz\bin to your environment variable PATH
run phpdoc
I don't like to have 184MB of usefull stuff on my PC just to run the 'dot' command?
Yes, its a lot of stuff. A more lightweight solution would be nice.

Resources