From 7940a327210ad61d4f046c6a12f9aa6da65be09c Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Wed, 4 Jan 2023 12:12:23 +0000 Subject: [PATCH] =?UTF-8?q?style:=20=F0=9F=8E=A8=20Minor=20formatting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 ++++++ src/config.rs | 16 +++++++--------- src/main.rs | 20 ++++++++++---------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 4f904f5..9fde0e8 100644 --- a/README.md +++ b/README.md @@ -146,6 +146,9 @@ Xtensa Rust toolchain will be installed under `/toolchains/esp`. Usage: espup install [OPTIONS] Options: + -p, --config-path + Path to where the espup configuration file will be written to + -d, --default-host Target triple of the host @@ -217,6 +220,7 @@ Options: Usage: espup uninstall [OPTIONS] Options: + -p, --config-path Path to where the espup configuration file will be written to -l, --log-level Verbosity level of the logs [default: info] [possible values: debug, info, warn, error] -h, --help Print help information -V, --version Print version information @@ -228,6 +232,8 @@ Options: Usage: espup update [OPTIONS] Options: + -p, --config-path + Path to where the espup configuration file will be written to -d, --default-host Target triple of the host [possible values: x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu, x86_64-pc-windows-msvc, x86_64-pc-windows-gnu, x86_64-apple-darwin, aarch64-apple-darwin] -l, --log-level diff --git a/src/config.rs b/src/config.rs index fce4779..260a6b9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -11,11 +11,6 @@ use std::{ path::PathBuf, }; -pub struct ConfigFile { - pub path: PathBuf, - pub config: Config, -} - /// Deserialized contents of a configuration file #[derive(Debug, Deserialize, Serialize, Default, Clone)] pub struct Config { @@ -37,10 +32,15 @@ pub struct Config { pub xtensa_rust: Option, } +pub struct ConfigFile { + pub path: PathBuf, + pub config: Config, +} + impl ConfigFile { + /// Construcs a new config file with the given path and config pub fn new(config_path: &Option, config: Config) -> Result { let config_path = config_path.clone().unwrap_or(Self::get_config_path()?); - Ok(ConfigFile { path: config_path, config, @@ -50,7 +50,6 @@ impl ConfigFile { /// Load the config from config file pub fn load(config_path: &Option) -> Result { let config_path = config_path.clone().unwrap_or(Self::get_config_path()?); - let config: Config = if let Ok(data) = read(&config_path) { toml::from_slice(&data).map_err(|_| Error::FailedToDeserialize)? } else { @@ -58,8 +57,7 @@ impl ConfigFile { config_path.to_string_lossy().into_owned(), )); }; - - ConfigFile::new(&Some(config_path), config) + Self::new(&Some(config_path), config) } /// Save the config to file diff --git a/src/main.rs b/src/main.rs index 869e2eb..1457e93 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,6 +57,9 @@ pub enum SubCommand { #[derive(Debug, Parser)] pub struct InstallOpts { + /// Path to where the espup configuration file will be written to. + #[arg(short = 'p', long)] + pub config_path: Option, /// Target triple of the host. #[arg(short = 'd', long, required = false, value_parser = ["x86_64-unknown-linux-gnu", "aarch64-unknown-linux-gnu", "x86_64-pc-windows-msvc", "x86_64-pc-windows-gnu" , "x86_64-apple-darwin" , "aarch64-apple-darwin"])] pub default_host: Option, @@ -80,9 +83,6 @@ pub struct InstallOpts { /// Relative or full path for the export file that will be generated. If no path is provided, the file will be generated under home directory (https://docs.rs/dirs/latest/dirs/fn.home_dir.html). #[arg(short = 'f', long)] pub export_file: Option, - /// The path to which the espup configuration file will be written to. - #[arg(short = 'p', long)] - pub config_path: Option, /// Comma or space list of extra crates to install. #[arg(short = 'c', long, required = false, value_parser = Crate::parse_crates)] pub extra_crates: Option>, @@ -111,6 +111,9 @@ pub struct InstallOpts { #[derive(Debug, Parser)] pub struct UpdateOpts { + /// Path to where the espup configuration file will be written to. + #[arg(short = 'p', long)] + pub config_path: Option, /// Target triple of the host. #[arg(short = 'd', long, required = false, value_parser = ["x86_64-unknown-linux-gnu", "aarch64-unknown-linux-gnu", "x86_64-pc-windows-msvc", "x86_64-pc-windows-gnu" , "x86_64-apple-darwin" , "aarch64-apple-darwin"])] pub default_host: Option, @@ -120,19 +123,16 @@ pub struct UpdateOpts { /// Xtensa Rust toolchain version. #[arg(short = 'v', long, value_parser = XtensaRust::parse_version)] pub toolchain_version: Option, - /// The path at which the espup configuration file can be found. - #[arg(short = 'p', long)] - pub config_path: Option, } #[derive(Debug, Parser)] pub struct UninstallOpts { + /// Path to where the espup configuration file will be written to. + #[arg(short = 'p', long)] + pub config_path: Option, /// Verbosity level of the logs. #[arg(short = 'l', long, default_value = "info", value_parser = ["debug", "info", "warn", "error"])] pub log_level: String, - /// The path at which the espup configuration file can be found. - #[arg(short = 'p', long)] - pub config_path: Option, } /// Installs the Rust for ESP chips environment @@ -278,7 +278,7 @@ async fn install(args: InstallOpts) -> Result<()> { }; let config_file = ConfigFile::new(&args.config_path, config)?; info!( - "{} Saving configuration file at {:?}", + "{} Storing configuration file at '{:?}'", emoji::WRENCH, config_file.path );