From 2b7c8114028073508963dfcc027cfd73cb0f113d Mon Sep 17 00:00:00 2001 From: JT <547158+jntrnr@users.noreply.github.com> Date: Wed, 27 Jul 2022 11:20:12 +1200 Subject: [PATCH] fix 0.66 nu-command crate (#6138) --- Cargo.lock | 2 +- Cargo.toml | 2 +- crates/nu-command/Cargo.toml | 2 +- crates/nu-command/src/default_context.rs | 1 - .../nu-command/src/env/config/config_reset.rs | 112 ------------------ crates/nu-command/src/env/config/mod.rs | 2 - crates/nu-command/src/env/mod.rs | 1 - 7 files changed, 3 insertions(+), 119 deletions(-) delete mode 100644 crates/nu-command/src/env/config/config_reset.rs diff --git a/Cargo.lock b/Cargo.lock index 942218139..00b38b6b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2554,7 +2554,7 @@ dependencies = [ [[package]] name = "nu-command" -version = "0.66.0" +version = "0.66.1" dependencies = [ "Inflector", "alphanumeric-sort", diff --git a/Cargo.toml b/Cargo.toml index 9b0321f88..e5b18c963 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,7 +41,7 @@ miette = "5.1.0" nu-ansi-term = "0.46.0" nu-cli = { path="./crates/nu-cli", version = "0.66.0" } nu-color-config = { path = "./crates/nu-color-config", version = "0.66.0" } -nu-command = { path="./crates/nu-command", version = "0.66.0" } +nu-command = { path="./crates/nu-command", version = "0.66.1" } nu-engine = { path="./crates/nu-engine", version = "0.66.0" } nu-json = { path="./crates/nu-json", version = "0.66.0" } nu-parser = { path="./crates/nu-parser", version = "0.66.0" } diff --git a/crates/nu-command/Cargo.toml b/crates/nu-command/Cargo.toml index fd7a2de46..08b63aca0 100644 --- a/crates/nu-command/Cargo.toml +++ b/crates/nu-command/Cargo.toml @@ -4,7 +4,7 @@ description = "Nushell's built-in commands" edition = "2021" license = "MIT" name = "nu-command" -version = "0.66.0" +version = "0.66.1" build = "build.rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/crates/nu-command/src/default_context.rs b/crates/nu-command/src/default_context.rs index 4be83f762..c113df36d 100644 --- a/crates/nu-command/src/default_context.rs +++ b/crates/nu-command/src/default_context.rs @@ -342,7 +342,6 @@ pub fn create_default_context() -> EngineState { WithEnv, ConfigNu, ConfigEnv, - ConfigReset, ConfigMeta, }; diff --git a/crates/nu-command/src/env/config/config_reset.rs b/crates/nu-command/src/env/config/config_reset.rs deleted file mode 100644 index b3f5fbc19..000000000 --- a/crates/nu-command/src/env/config/config_reset.rs +++ /dev/null @@ -1,112 +0,0 @@ -use chrono::Local; -use nu_protocol::{ - ast::Call, - engine::{Command, EngineState, Stack}, - Category, Example, PipelineData, ShellError, Signature, -}; -use std::io::Write; - -#[derive(Clone)] -pub struct ConfigReset; - -impl Command for ConfigReset { - fn name(&self) -> &str { - "config reset" - } - - fn signature(&self) -> Signature { - Signature::build(self.name()) - .switch("nu", "reset only nu config, config.nu", Some('n')) - .switch("env", "reset only env config, env.nu", Some('e')) - .switch("without-backup", "do not make a backup", Some('w')) - .category(Category::Env) - } - - fn usage(&self) -> &str { - "Reset nushell environment configurations to default, and saves old config files in the config location as oldconfig.nu and oldenv.nu" - } - - fn examples(&self) -> Vec { - vec![Example { - description: "reset nushell configuration files", - example: "config reset", - result: None, - }] - } - - fn run( - &self, - _engine_state: &EngineState, - _stack: &mut Stack, - call: &Call, - _input: PipelineData, - ) -> Result { - let only_nu = call.has_flag("nu"); - let only_env = call.has_flag("env"); - let no_backup = call.has_flag("without-backup"); - let span = call.head; - let mut config_path = match nu_path::config_dir() { - Some(path) => path, - None => { - return Err(ShellError::GenericError( - "Could not find config path".to_string(), - "Could not find config path".to_string(), - None, - None, - Vec::new(), - )); - } - }; - config_path.push("nushell"); - if !only_env { - let mut nu_config = config_path.clone(); - nu_config.push("config.nu"); - let config_file = include_str!("../../../../../docs/sample_config/default_config.nu"); - if !no_backup { - let mut backup_path = config_path.clone(); - backup_path.push(format!( - "oldconfig-{}.nu", - Local::now().format("%F-%H-%M-%S"), - )); - if std::fs::rename(nu_config.clone(), backup_path).is_err() { - return Err(ShellError::FileNotFoundCustom( - "config.nu could not be backed up".into(), - span, - )); - } - } - if let Ok(mut file) = std::fs::File::create(nu_config) { - if writeln!(&mut file, "{}", config_file).is_err() { - return Err(ShellError::FileNotFoundCustom( - "config.nu could not be written to".into(), - span, - )); - } - } - } - if !only_nu { - let mut env_config = config_path.clone(); - env_config.push("env.nu"); - let config_file = include_str!("../../../../../docs/sample_config/default_env.nu"); - if !no_backup { - let mut backup_path = config_path.clone(); - backup_path.push(format!("oldenv-{}.nu", Local::now().format("%F-%H-%M-%S"),)); - if std::fs::rename(env_config.clone(), backup_path).is_err() { - return Err(ShellError::FileNotFoundCustom( - "env.nu could not be backed up".into(), - span, - )); - } - } - if let Ok(mut file) = std::fs::File::create(env_config) { - if writeln!(&mut file, "{}", config_file).is_err() { - return Err(ShellError::FileNotFoundCustom( - "env.nu could not be written to".into(), - span, - )); - } - } - } - Ok(PipelineData::new(span)) - } -} diff --git a/crates/nu-command/src/env/config/mod.rs b/crates/nu-command/src/env/config/mod.rs index 9cd93d249..5e70f6315 100644 --- a/crates/nu-command/src/env/config/mod.rs +++ b/crates/nu-command/src/env/config/mod.rs @@ -1,9 +1,7 @@ mod config_; mod config_env; mod config_nu; -mod config_reset; mod utils; pub use config_::ConfigMeta; pub use config_env::ConfigEnv; pub use config_nu::ConfigNu; -pub use config_reset::ConfigReset; diff --git a/crates/nu-command/src/env/mod.rs b/crates/nu-command/src/env/mod.rs index 6bd891485..e0e1a1820 100644 --- a/crates/nu-command/src/env/mod.rs +++ b/crates/nu-command/src/env/mod.rs @@ -7,7 +7,6 @@ mod with_env; pub use config::ConfigEnv; pub use config::ConfigMeta; pub use config::ConfigNu; -pub use config::ConfigReset; pub use env_command::Env; pub use let_env::LetEnv; pub use load_env::LoadEnv;