Skip to content
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

Refactors #26

Merged
merged 7 commits into from
Apr 6, 2024
Merged
Changes from 1 commit
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
Next Next commit
chore: move rustup handling to a separate module
paolobarbolini committed Apr 6, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 0a6283126f76718e8f74ebcbdf4c81334acc4b82
15 changes: 3 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@ use sha2::{Digest as _, Sha256, Sha512};
use tar::Archive;
use url::Url;

mod rustup;

const USER_AGENT: &str = concat!(
env!("CARGO_PKG_NAME"),
"/",
@@ -42,18 +44,7 @@ fn main() -> Result<()> {
.user_agent(USER_AGENT)
.build()?;

let default_toolchain = Command::new("rustup")
.arg("default")
.output()
.ok()
.filter(|out| out.status.success())
.and_then(|out| String::from_utf8(out.stdout).ok())
.and_then(|stdout| {
stdout
.split_once(' ')
.map(|(toolchain, _)| toolchain.to_owned())
})
.unwrap_or_else(|| "stable".to_owned());
let default_toolchain = self::rustup::default_toolchain();

let crates_io_index = "https://github.com/rust-lang/crates.io-index".parse::<Url>()?;

17 changes: 17 additions & 0 deletions src/rustup.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use std::process::Command;

/// Get the default rustup toolchain or `stable` if the default can't be determined
pub fn default_toolchain() -> String {
Command::new("rustup")
.arg("default")
.output()
.ok()
.filter(|out| out.status.success())
.and_then(|out| String::from_utf8(out.stdout).ok())
.and_then(|stdout| {
stdout
.split_once(' ')
.map(|(toolchain, _)| toolchain.to_owned())
})
.unwrap_or_else(|| "stable".to_owned())
}