Fix editing broken configuration (fix #241)
This commit is contained in:
@@ -166,6 +166,12 @@ pub struct CommandLineArgs {
|
|||||||
yes: bool,
|
yes: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl CommandLineArgs {
|
||||||
|
pub fn edit_config(&self) -> bool {
|
||||||
|
self.edit_config
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Represents the application configuration
|
/// Represents the application configuration
|
||||||
///
|
///
|
||||||
/// The struct holds the loaded configuration file, as well as the arguments parsed from the command line.
|
/// The struct holds the loaded configuration file, as well as the arguments parsed from the command line.
|
||||||
@@ -181,9 +187,7 @@ impl Config {
|
|||||||
/// Load the configuration.
|
/// Load the configuration.
|
||||||
///
|
///
|
||||||
/// The function parses the command line arguments and reading the configuration file.
|
/// The function parses the command line arguments and reading the configuration file.
|
||||||
pub fn load(base_dirs: &BaseDirs) -> Result<Self, Error> {
|
pub fn load(base_dirs: &BaseDirs, opt: CommandLineArgs) -> Result<Self, Error> {
|
||||||
let opt = CommandLineArgs::from_args();
|
|
||||||
|
|
||||||
let mut builder = formatted_timed_builder();
|
let mut builder = formatted_timed_builder();
|
||||||
|
|
||||||
if opt.verbose {
|
if opt.verbose {
|
||||||
@@ -292,11 +296,6 @@ impl Config {
|
|||||||
self.opt.keep_at_end || env::var("TOPGRADE_KEEP_END").is_ok()
|
self.opt.keep_at_end || env::var("TOPGRADE_KEEP_END").is_ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether to edit the configuration file
|
|
||||||
pub fn edit_config(&self) -> bool {
|
|
||||||
self.opt.edit_config
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Whether to set the terminal title
|
/// Whether to set the terminal title
|
||||||
pub fn set_title(&self) -> bool {
|
pub fn set_title(&self) -> bool {
|
||||||
self.config_file.set_title.unwrap_or(true)
|
self.config_file.set_title.unwrap_or(true)
|
||||||
|
|||||||
11
src/main.rs
11
src/main.rs
@@ -10,7 +10,7 @@ mod steps;
|
|||||||
mod terminal;
|
mod terminal;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
use self::config::{Config, Step};
|
use self::config::{CommandLineArgs, Config, Step};
|
||||||
use self::error::{Error, ErrorKind};
|
use self::error::{Error, ErrorKind};
|
||||||
use self::report::Report;
|
use self::report::Report;
|
||||||
use self::steps::*;
|
use self::steps::*;
|
||||||
@@ -24,6 +24,7 @@ use std::env;
|
|||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
use structopt::StructOpt;
|
||||||
|
|
||||||
fn execute<'a, F, M>(report: &mut Report<'a>, key: M, func: F, no_retry: bool) -> Result<(), Error>
|
fn execute<'a, F, M>(report: &mut Report<'a>, key: M, func: F, no_retry: bool) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
@@ -65,14 +66,16 @@ fn run() -> Result<(), Error> {
|
|||||||
ctrlc::set_handler();
|
ctrlc::set_handler();
|
||||||
|
|
||||||
let base_dirs = directories::BaseDirs::new().ok_or(ErrorKind::NoBaseDirectories)?;
|
let base_dirs = directories::BaseDirs::new().ok_or(ErrorKind::NoBaseDirectories)?;
|
||||||
let config = Config::load(&base_dirs)?;
|
|
||||||
terminal::set_title(config.set_title());
|
|
||||||
|
|
||||||
if config.edit_config() {
|
let opt = CommandLineArgs::from_args();
|
||||||
|
if opt.edit_config() {
|
||||||
Config::edit(&base_dirs)?;
|
Config::edit(&base_dirs)?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let config = Config::load(&base_dirs, opt)?;
|
||||||
|
terminal::set_title(config.set_title());
|
||||||
|
|
||||||
if config.run_in_tmux() && env::var("TOPGRADE_INSIDE_TMUX").is_err() {
|
if config.run_in_tmux() && env::var("TOPGRADE_INSIDE_TMUX").is_err() {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user