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

Custom and interactive install #293

Merged
merged 5 commits into from
Apr 17, 2016
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
2 changes: 2 additions & 0 deletions Cargo.lock

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

55 changes: 55 additions & 0 deletions src/rustup-cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,61 @@ pub fn confirm(question: &str, default: bool) -> Result<bool> {
Ok(r)
}

pub enum Confirm {
Yes, No, Advanced
}

pub fn confirm_advanced(default: Confirm) -> Result<Confirm> {
let _ = std::io::stdout().flush();
let input = try!(read_line());

let r = match &*input {
"y" | "Y" | "yes" => Confirm::Yes,
"n" | "N" | "no" => Confirm::No,
"a" | "A" | "advanced" => Confirm::Advanced,
"" => default,
_ => Confirm::No,
};

println!("");

Ok(r)
}

pub fn question_str(question: &str, default: &str) -> Result<String> {
println!("{}", question);
let _ = std::io::stdout().flush();
let input = try!(read_line());

println!("");

if input.is_empty() {
Ok(default.to_string())
} else {
Ok(input)
}
}

pub fn question_bool(question: &str, default: bool) -> Result<bool> {
println!("{}", question);

let _ = std::io::stdout().flush();
let input = try!(read_line());

println!("");

if input.is_empty() {
Ok(default)
} else {
match &*input {
"y" | "Y" | "yes" => Ok(true),
"n" | "N" | "no" => Ok(false),
_ => Ok(default)
}
}

}

pub fn read_line() -> Result<String> {
let stdin = std::io::stdin();
let stdin = stdin.lock();
Expand Down
8 changes: 6 additions & 2 deletions src/rustup-cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,14 @@ fn run_multirust() -> Result<()> {
// ~/.multirust/tmp/multirust-$random, and execute it with
// `self install` as the arguments. FIXME: Verify this
// works.
let opts = self_update::InstallOpts {
default_toolchain: "stable".to_string(),
no_modify_path: false,
};
if cfg!(windows) {
self_update::install(false, false, "stable")
self_update::install(false, false, opts)
} else {
self_update::install(true, false, "stable")
self_update::install(true, false, opts)
}
}
Some(_) => {
Expand Down
Loading