Add -k flag

This commit is contained in:
Roey Darwish Dror
2019-06-16 09:09:05 +03:00
parent a834a79f45
commit b6e838bab0
4 changed files with 15 additions and 5 deletions

View File

@@ -5,7 +5,7 @@ use lazy_static::lazy_static;
use serde::Deserialize;
use shellexpand;
use std::collections::{BTreeMap, HashMap};
use std::fs;
use std::{env, fs};
use structopt::StructOpt;
use toml;
@@ -125,6 +125,10 @@ pub struct CommandLineArgs {
/// Output logs
#[structopt(short = "v", long = "verbose")]
verbose: bool,
/// Prompt or a key before exiting
#[structopt(short = "k", long = "keep")]
keep_at_end: bool,
}
/// Represents the application configuration
@@ -207,4 +211,9 @@ impl Config {
pub fn remote_topgrades(&self) -> &Option<Vec<String>> {
&self.config_file.remote_topgrades
}
/// Prompt for a key before exiting
pub fn keep_at_end(&self) -> bool {
self.opt.keep_at_end || env::var("TOPGRADE_KEEP_END").is_ok()
}
}

View File

@@ -498,8 +498,8 @@ fn run() -> Result<(), Error> {
freebsd::audit_packages(&sudo).ok();
}
if env::var("TOPGRADE_KEEP_END").is_ok() {
print_info("\nPress R to reboot, S for shell or any other key to continue");
if config.keep_at_end() {
print_info("\n(R)eboot\n(S)hell\n\nPress any other key to continue");
match get_char() {
's' | 'S' => {
run_shell();

View File

@@ -131,5 +131,6 @@ pub fn run_sdkman(base_dirs: &BaseDirs, cleanup: bool, run_type: RunType) -> Res
}
pub fn reboot() {
Command::new("sudo").arg("reboot").spawn().ok();
print!("Rebooting...");
Command::new("sudo").arg("reboot").spawn().unwrap().wait().unwrap();
}

View File

@@ -92,7 +92,7 @@ impl Terminal {
fn print_info<P: AsRef<str>>(&mut self, message: P) {
let message = message.as_ref();
self.term
.write_fmt(format_args!("{}\n", style(message).yellow().bold()))
.write_fmt(format_args!("{}\n", style(message).blue().bold()))
.ok();
}