kevincobain2000 / gobrew

Go version manager, written in Go. Super simple tool to install and manage Go versions. Install go without root. Gobrew doesn't require shell rehash.
https://medium.com/web-developer/go-version-manager-gobrew-c8750157dfe6
MIT License
369 stars 24 forks source link

RFC: `gobrew` interactive #145

Closed kevincobain2000 closed 11 months ago

kevincobain2000 commented 11 months ago

RFC

To add interactive behaviour so I don't have to remember commands like gobrew use mod gobrew use latest or even gobrew ls and gobrew ls-remote to check what version I am on etc and etc.

Current situation

On command gobrew, no args, it displays help menu right now.

Proposal

On hitting gobrew, it presents an interactive info as below:

Case 1: Fresh install, from inside a directory with go.mod

$ gobrew
Installed GO version          ...... None
Latest GO version             ...... 1.21.3
Mod GO version                ...... 1.20

Go is not installed, your dir has go.mod file
Do you want to install 1.20 (y/n)

Case 2: Fresh install, from outside a directory with go.mod

$ gobrew
Installed GO version          ...... None
Latest GO version             ...... 1.21.3
Mod GO version                ...... None

Go is not installed
Do you want to install latest Go version 1.21.3 (y/n)

Case 3: Go is installed, but not latest version

$ gobrew
Installed GO version          ...... 1.20
Latest GO version             ...... 1.21.3
Mod GO version                ...... None

Your Go version is not latest
Do you want to install latest Go version 1.21.3 (y/n)

Case 4: Go is installed, but not latest version, but matches mod file

$ gobrew
Installed GO version          ...... 1.20
Latest GO version             ...... 1.21.3
Mod GO version                ...... 1.20

Your Go version and go.mod file matches!
Do you want to install latest Go version 1.21.3 and update mod file (y/n)

Case 5: Go is installed, on latest version, but doesn't match mod file

$ gobrew
Installed GO version          ...... 1.21.3
Latest GO version             ...... 1.21.3
Mod GO version                ...... 1.20

Your Go version and go.mod file doesn't match.
Do you want to update mod file (y/n)
  -> Do you want to downgrade go version (y/n) (if above answer is no)

-- 1) Above can be obtained on hitting gobrew. 1.1) Additionally, could add --no-interactive y|n option as well. But I don't think that would be necessary at this point. 2) Or if intractive is too much, then we could consider atleast gobrew info that will only display out info.

juev commented 11 months ago

Hello!

An interesting idea, but I don’t really understand what its essence is yet. Are we trying to provide some logic to the user? We don't have too many teams to get confused about.

According to the given options. The first option is clear, but what if I want to install the latest version of go in the project directory with go.mod?

The second case is not clear to me. If we are outside the directory with the go.mod file, how are we supposed to know to use a certain configuration? If I understand everything correctly, then for the second case the third given option will be used.

There are still too many questions about the logic of work.

kevincobain2000 commented 11 months ago

Ah sorry. In Case 2, go.mod version will also be none. I have edited.

kevincobain2000 commented 11 months ago

The purpose of this is that a user will be able to achieve what he wants to achieve just by executing gobrew with no args.

juev commented 11 months ago

I think it looks good.

kevincobain2000 commented 11 months ago

Thanks for checking @juev I ll work on it.

gedw99 commented 11 months ago

+1

This will be useful in CI too I think

kevincobain2000 commented 11 months ago

Thanks @gedw99

gedw99 commented 11 months ago

Was thinking a —output=json would be nice too. Then it’s easy to use in CI and possibly other use cases that are not known yet.

than it possible to parse the json on the call side and react to the output.

maybe layer a golang client that understands the json in a strongly type way too.

basically I realise it’s jsonrpc style with client and server .

there are some great golang libs that do all the grunt work for json rpc out there in GitHub btw.

kevincobain2000 commented 11 months ago

Thanks @gedw99

JSON output could be nice, and I also find hard time finding it's use case. Only use case I can think of is for the infra/dev-ops/SRE-admin teams, who develop their admin portals inside their companies to just list up some GO versions in a dropdown. Other than that, I don't know, if JSON output is really necessary and people want to use it on CI with jq