Skip to content

Commit

Permalink
Removed libgit due to dependency on openssl
Browse files Browse the repository at this point in the history
  • Loading branch information
x0f5c3 committed Dec 24, 2020
1 parent 817274a commit 0a590aa
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 119 deletions.
13 changes: 2 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,10 @@


# v0.7.0 (2020-12-24):
- [Removed] libgit due to dependency on openssl
- [Added] interactive mode, choosing version
- [Added] new options to git journal
- [Changed] git journal
- [Feature] add option to choose specific version
- [Removed] test download
- [Modified] gitignore to exclude target
- [Feature] Use manic and switch to libgit
- [Update] main.rs
- [Update] README.md
- [Add] new version to changelog
- [Add] codecov badge
- [Added] new changelog, modified gitignore, formatted
- [Removed] openssl to easier compile on musl targets
- [Feature] Use manic

# v0.6.5 (2020-12-11):
- [Removed] openssl to easier compile on musl targets
Expand Down
115 changes: 27 additions & 88 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ structopt = "0.3.21"
console = "0.13.0"
manic = { version = "0.2.3", features = ["progress"] }
thiserror = "1.0.22"
git2 = { version = "0.13.14", default-features = false, features = ["https", "vendored-openssl"] }
dialoguer = "0.7.1"
quit = "1.1.2"
duct = "*"
leg = "0.4.1"
colored = "^1.8.0"
[dependencies.reqwest]
Expand Down
2 changes: 0 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ pub enum Error {
PathBufErr,
#[error("Failed to get version")]
NoVersion,
#[error("Git error: {0}")]
GitError(#[from] git2::Error),
#[error("No sha256 found")]
NoSha,
#[error("Failed to parse version")]
Expand Down
32 changes: 20 additions & 12 deletions src/goversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::path::PathBuf;
use versions::Versioning;
use crate::error::Error;
use manic::progress::downloader;
use git2::{Remote, Direction};
use duct::cmd;
#[cfg(target_os = "linux")]
static FILE_EXT: &str = "linux-amd64.tar.gz";
#[cfg(target_os = "windows")]
Expand All @@ -29,17 +29,15 @@ pub struct GoVersion {
impl GoVersion {
/// Gets golang versions from git tags
fn get_git_versions() -> Result<Vec<String>, Error> {
let mut detached = Remote::create_detached("https://github.com/golang/go")?;
detached.connect(Direction::Fetch)?;
let output = detached.list()?;
let tags: Vec<String> = output
.iter()
.map(|x| x.name().trim())
.filter(|x| x.contains("go"))
.map(|x| x.split('/').nth(2).unwrap())
.map(|x| x.replace("go", ""))
.collect();
Ok(tags)
let output: Vec<String> = cmd!("git", "ls-remote", "--tags", "https://github.com/golang/go").read()?
.trim()
.lines()
.filter(|x| x.contains("go"))
.filter_map(|x| x.split('\t').nth(1))
.filter_map(|x| x.split('/').nth(2))
.map(|x| x.replace("go", ""))
.collect();
Ok(output)
}
/// Parses the versions into Versioning structs
pub fn get_versions() -> Result<Vec<Versioning>, Error> {
Expand Down Expand Up @@ -119,3 +117,13 @@ impl GoVersion {
})
}
}

pub fn check_git() -> bool {
match cmd!("git", "version").stdout_null().run() {
Ok(_) => return true,
Err(e) => match e.kind() {
std::io::ErrorKind::NotFound => return false,
_ => return true,
}
}
}
27 changes: 22 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use colored::Colorize;
use console::Term;
use dialoguer::{theme::ColorfulTheme, Select};
use error::Error;
use goversion::GoVersion;
use goversion::{check_git, GoVersion};
use human_panic::setup_panic;
use std::path::PathBuf;
use structopt::StructOpt;
Expand All @@ -30,14 +30,24 @@ async fn main() -> Result<(), Error> {
setup_panic!();
let opt = Opt::from_args();
let term = Term::stdout();
let git_present = check_git();
let golang = {
if let Some(vers) = opt.version {
goversion::GoVersion::version(vers).await?
} else if opt.interactive {
} else if opt.interactive && git_present {
let vers = ask_for_version(&term)?;
goversion::GoVersion::version(vers).await?
} else {
goversion::GoVersion::latest().await?
if git_present {
goversion::GoVersion::latest().await?
} else {
leg::error(
"You requested the latest version and git is not installed, please install git",
None,
None,
);
quit::with_code(127);
}
}
};
format!("Downloading golang version {}", &golang.version);
Expand All @@ -50,7 +60,10 @@ async fn main() -> Result<(), Error> {
None,
);
let file_path = golang.download(opt.output, opt.workers).await?;
let path_str = file_path.to_str().expect("Couldn't convert path to str").to_string();
let path_str = file_path
.to_str()
.expect("Couldn't convert path to str")
.to_string();
leg::success(
&format!("Golang has been downloaded to {}", path_str),
None,
Expand All @@ -74,7 +87,11 @@ fn ask_for_version(term: &Term) -> Result<Versioning, Error> {
if let Some(index) = selection {
Ok(versions[index].clone())
} else {
leg::error(&format!("{}", "You didn't select anything".red().bold()), None, None);
leg::error(
&format!("{}", "You didn't select anything".red().bold()),
None,
None,
);
quit::with_code(127);
}
}
Expand Down

0 comments on commit 0a590aa

Please sign in to comment.