Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- Search available version of Go.
- Manage locally cache files(such as `*.tar.gz`, `*.tar.gz.sha256`).
- Upgrade `goup` itself.
- Customize `GOUP_HOME`(default `$HOME/.goup`)(>= v0.11.x);
- Friendly prompt.
- Should be pretty fast.

Expand Down Expand Up @@ -258,6 +259,9 @@ Default log level is `Info`. You can use `goup -v <subcommand>` or `goup -vv <su
resolved v0.10.3 above.
more information see [issue #251](https://github.com/thinkgos/goup-rs/issues/251)

- How to customize `GOUP_HOME`? (>= v0.11.x)
`goup` use the `$HOME/.goup` directory as `GOUP_HOME`. if you want to customize the `GOUP_HOME`(most are Windows users), you can set `GOUP_HOME` environment variable to use another directory, before install `goup`, make sure you has set the customize `GOUP_HOME` environment variable and the target directory permissions, otherwise, it may lead to surprising results, refer issue [#265](https://github.com/thinkgos/goup-rs/issues/265) [#270](https://github.com/thinkgos/goup-rs/pull/270)

## License

[Apache 2.0](LICENSE)
8 changes: 6 additions & 2 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
- 支持搜索可用的Go版本.
- 支持管理本地缓存文件(如 `*.tar.gz`, `*.tar.gz.sha256`).
- 支持`goup`自我更新.
- 支持自定义`GOUP_HOME`(默认`$HOME/.goup`)(>= v0.11.x);
- 友好的提示.
- 应该很快.

`goup` 是对上述特性的一种尝试其灵感主要来自于 [Rustup](https://rustup.rs/), [golang/dl](https://github.com/golang/dl), [goup](https://github.com/owenthereal/goup), [goenv](https://github.com/syndbg/goenv), [gvm](https://github.com/moovweb/gvm) and [getgo](https://github.com/golang/tools/tree/master/cmd/getgo).
`goup` 是对上述特性的一种尝试, 其灵感主要来自于 [Rustup](https://rustup.rs/), [golang/dl](https://github.com/golang/dl), [goup](https://github.com/owenthereal/goup), [goenv](https://github.com/syndbg/goenv), [gvm](https://github.com/moovweb/gvm) and [getgo](https://github.com/golang/tools/tree/master/cmd/getgo).

## 安装

Expand Down Expand Up @@ -243,7 +244,7 @@ goup completion zsh > _goup
- 编译和安装源代码失败?
所需的Go最低版本取决于Go的目标版本, 更多信息请参见[source installation instructions](https://go.dev/doc/install/source)
- [`semver`](https://semver.org/)
- exact(`=`): 允许更新到与版本完全一致的最新版本, 因此`=1.21.4`表示与版本`1.21.4`完全一致
- exact(`=`): 允许更新到与版本完全一致的最新版本, 因此`=1.21.4`表示与版本`1.21.4`完全一致.
- greater(`>`): 允许更新到大于该版本的最新版本, 因此`>1.21.4`表示大于`1.21.4`.
- greater equal(`>=`): 允许更新到大于或等于该版本的最新版本, 因此 `>1.21.4` 表示大于或等于`1.21.4`.
- less(`<`): 允许更新到小于该版本的最新版本, 因此`>1.21.4`表示大于`1.21.4`.
Expand All @@ -258,6 +259,9 @@ goup completion zsh > _goup
大于v0.10.3版本已解决.
看多信息查看[issue #251](https://github.com/thinkgos/goup-rs/issues/251)

- 如何自定义 `GOUP_HOME`? (>= v0.11.x)
`goup`使用`$HOME/.goup`目录作为 `GOUP_HOME`. 如果需要自定义`GOUP_HOME`(大多数是Windows用户), 可以设置`GOUP_HOME`环境变量来使用其他目录, 安装`goup`之前, 请确保已设置自定义`GOUP_HOME`环境变量和目标目录权限, 否则可能会导致令人惊讶的结果, 请参阅issue [#265](https://github.com/thinkgos/goup-rs/issues/265) [#270](https://github.com/thinkgos/goup-rs/pull/270)

## 许可证

[Apache 2.0](LICENSE)
1 change: 1 addition & 0 deletions goup-version/src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::env;

pub const GOUP_HOME: &str = "GOUP_HOME";
pub const GOUP_GO_HOST: &str = "GOUP_GO_HOST";
pub const GOUP_GO_DOWNLOAD_BASE_URL: &str = "GOUP_GO_DOWNLOAD_BASE_URL";
pub const GOUP_GO_SOURCE_GIT_URL: &str = "GOUP_GO_SOURCE_GIT_URL";
Expand Down
28 changes: 23 additions & 5 deletions goup-version/src/dir.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use std::{
fs,
fs::File,
env,
fs::{self, File},
ops::{Deref, DerefMut},
path::{Path, PathBuf},
};

use anyhow::anyhow;

use super::consts::GOUP_HOME;

/// Dir `${path}/.goup` contain a `PathBuf`.
#[derive(Debug, Clone, PartialEq)]
pub struct Dir {
Expand All @@ -16,17 +18,25 @@ pub struct Dir {
impl Dir {
/// Returns the path to the user's home directory.
pub fn home_dir() -> Result<PathBuf, anyhow::Error> {
dirs::home_dir().ok_or_else(|| anyhow!("where is home"))
dirs::home_dir().ok_or_else(|| anyhow!("home dir get failed"))
}
/// Allocates a Dir as `${path}/.goup`
pub fn new<P: AsRef<Path>>(p: P) -> Self {
let mut path: PathBuf = p.as_ref().into();
path.push(".goup");
Self { path }
}
/// Allocates a `GOUP_HOME` Dir as `${HOME}/.goup`
/// Allocates a `GOUP_HOME` Dir as Environment Or `${HOME}/.goup`
pub fn goup_home() -> Result<Self, anyhow::Error> {
Ok(Self::new(Self::home_dir()?))
env::var(GOUP_HOME)
.ok()
.filter(|s| !s.is_empty())
.map(|s| {
Ok(Self {
path: PathBuf::from(s),
})
})
.unwrap_or_else(|| Self::home_dir().map(Self::new))
}
// Creates an owned [`Dir`] with `path` adjoined to `self`.
pub fn join_path<P: AsRef<Path>>(&self, path: P) -> Self {
Expand Down Expand Up @@ -120,6 +130,14 @@ impl DerefMut for Dir {
}
}

impl Default for Dir {
fn default() -> Self {
Self {
path: PathBuf::new(),
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
13 changes: 8 additions & 5 deletions goup/setup_env_unix
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
#!/bin/sh

local GOUP_HOME=${GOUP_HOME:-$HOME/.goup}

# goup shell setup
# affix colons on either side of $PATH to simplify matching
case ":${PATH}:" in
*:"$HOME/.goup/current/bin":*)
*:"$GOUP_HOME/current/bin":*)
;;
*)
# Prepending path in case a system-installed go needs to be overridden
export GOROOT=$HOME/.goup/current
export GOROOT=$GOUP_HOME/current
export PATH=$PATH:$GOROOT/bin
;;
esac

# affix colons on either side of $PATH to simplify matching
case ":${PATH}:" in
*:"$HOME/.goup/bin":*)
*:"$GOUP_HOME/bin":*)
;;
*)
# Prepending path in case a system-installed rustc needs to be overridden
export PATH="$HOME/.goup/bin:$PATH"
export PATH="$GOUP_HOME/bin:$PATH"
;;
esac
esac
7 changes: 6 additions & 1 deletion goup/src/command/env.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::Args;
use goup_version::consts;
use goup_version::{Dir, consts};
use prettytable::{Table, row};

use super::Run;
Expand All @@ -12,6 +12,11 @@ impl Run for Env {
let mut table = Table::new();

table.add_row(row!["Key", "Value", "Explain"]);
table.add_row(row![
consts::GOUP_HOME,
Dir::goup_home().unwrap_or_default().to_string_lossy(),
"Get goup home directory, default: '$HOME/.goup'",
]);
table.add_row(row![
consts::GOUP_GO_HOST,
consts::go_host(),
Expand Down
10 changes: 5 additions & 5 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ function main() {
local dld=$(get_dld)

local _url="https://github.com/thinkgos/goup-rs/releases/latest/download/${_target}"
local GOUP_DIR="$HOME/.goup"
local GOUP_BIN_DIR="${GOUP_DIR}/bin"
local GOUP_BIN_FILE="${GOUP_DIR}/bin/goup"
local GOUP_HOME=${GOUP_HOME:-$HOME/.goup}
local GOUP_BIN_DIR="${GOUP_HOME}/bin"
local GOUP_BIN_FILE="${GOUP_HOME}/bin/goup"

local _dir
if ! _dir="$(ensure mktemp -d)"; then
Expand All @@ -144,7 +144,7 @@ function main() {
fi
local _target_file="${_dir}/${_target}"

ensure mkdir -p ${GOUP_DIR}
ensure mkdir -p ${GOUP_HOME}
ensure mkdir -p ${GOUP_BIN_DIR}

echo "[1/3] Download goup..."
Expand All @@ -162,7 +162,7 @@ function main() {
ignore rm "$_target_file"
ignore rmdir "$_dir"

echo "[3/3] Please add '. "\$HOME/.goup/env"' to your shell environment!!"
echo "[3/3] Please add '. "${GOUP_HOME}/env"' to your shell environment!!"
echo " And then try to run 'goup --version'"
}

Expand Down