-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add use command to switch version #12
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @feualpha, thanks for your contribution!
Before we continue, let's make the PR against the next
branch. I already changed the PR but you will need to rebase and fix a conflict in the README
After thinking about it for a while, I've changed my mind about the approach to the "new" API:
- Let's better use
set
instead ofuse
. The latter sounds more like to what the currentg run
command does. - Let's create another command:
download
, which will only download the given version but notset
it. - The
install
command, shoulddownload
andset
the given version without doubting (no--download
flag).
To achieve this, we will need to create a new function that only downloads, let's call it download_version
and rename the current download
function to download_file
for clarity, since that's what the function does.
Some extra bits:
- As a side effect, the
ACTIVATE
variable should go away entirely. - The
activate
function which is called by theset
command, should check if the version actually exists in the.versions
dir and throw an "Version X is not available. Use 'g install X' to install it." - To normalize the naming of the functions, let's name/rename them
set_version
,install_version
anddownload_version
The rationale here is that install
should keep doing what it currently does and should be the main command users will use 99% of the time, but we should provide "porcelain" commands as escape hatches and discovery tools. Also, the deletion of the --download
flag in favor of function/command composition is more elegant.
Let me know if something isn't clear
hi @stefanmaric i have push some changes, please check it out. |
You're right, it is a bit messed up now. Will leave you some suggestions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@feualpha thanks for your patience.
We almost done. I left a few outstanding tweaks, but otherwise this is looking pretty good.
bin/g
Outdated
@@ -569,6 +573,8 @@ activate() { | |||
done | |||
|
|||
ln -sf "$GOROOT/bin/"* "$GOPATH/bin/" | |||
|
|||
log_info "set" "$version" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@feualpha let's remove this one.
bin/g
Outdated
echo | ||
log_info "installing" "$version" | ||
log_info "downloading" "$version" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's re-rephrase to "selected"; this log has been important mainly to denote what version was resolved when using the latest
keyword.
fi | ||
|
||
download_version $version | ||
set_version $version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@feualpha let's add a log_info here with installed
and $(go version)
; this is mainly to confirm to the user the intended version was installed, in case something is off and the selected version is not actually activated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean this bit:
if [ "$version" = "latest" ]; then
version=$(get_latest_version)
fi
It is being repeated quite a bit, but it is OK.
install() { | ||
install_version() { | ||
version=$1 | ||
dir="$GO_VERSIONS_DIR/$version" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before setting this, we have to resolve the latest
version in case such keyword was used. Same for the set version.
Since we would be giving false positive since $GO_VERSIONS_DIR/latest
is not an actual thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i see. i miss this one
@feualpha and also: can you squash all these changes once ready and craft a concise commit title and body to summarize the changes? |
@@ -556,11 +556,15 @@ open_interactive_ui() { | |||
# Activate <version> | |||
# | |||
|
|||
activate() { | |||
set_version() { | |||
version=$1 | |||
active=$(get_current_version) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@feualpha only another check of latest
here missing. Otherwise it looks good to merge. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes, the consequence of exposing it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should i make it something like this? since it's already duplicated more then 3 times
resolve_version_arg(){
$version_arg=$1
if [ "$version_arg" = "latest" ]; then
echo $(get_latest_version)
else
echo $version_arg
fi
}
version_args=$1
version=$(resolve_version_arg "$version_arg")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@feualpha ok, let's do it. I usually avoid nesting calls too much since error handling in shell scripting is horrible, but since we are doing command substitution there already, it won't make it worse.
Let's compact it a bit:
resolve_version_argument() {
if [ "$1" = "latest" ]; then
get_latest_version
else
echo "$1"
fi
}
And inside the <x>_version
functions, a single line:
version=$(resolve_version_argument "$1")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And @feualpha will need to you to rebase this branch on top of next
since I just merged #10 which has been in the works for a while now.
This changes implement the suggestion from issue stefanmaric#8 to add specific command to switch between go version. previously it can be done by using `g` interactive mode or by using `g install <version>`. the problem comes from `g install <version>` command, because this command is also used to download the specified go version. therefore `g set <version>` is added. This changes also add `g download <version>` to download the specified go version without activating it. this command replace `g install <version> --download`. the goal of this change is to make the install function to be more conceise.
@feaulpha thanks for your patience and your contribution! ❤️ I'll be releasing this along some other things sometime soon. Stay tuned! |
- Warn users about existing go installations - Improve self-upgrade script - Improve previous installation detection on g-install - Make self-upgrade throw if g was not installed via g-install - Add alias collision detection and setup helper (#11, thanks @alvinmatias69) - Add `download` and `set` commands (#12, thanks @feualpha) * BREAKING: Remove the `--download` option - Add Makefile with lint and format targets for better DX - Fix shellcheck lint errors - Format source code using make format - Improve and update docs to reflect latest contributions
set
command to switch between go version,download
command to replaceg install <version> --download
suggestion from #8