From 8fb3588619e7c97080f6be61f2a2032d25f39f4e Mon Sep 17 00:00:00 2001 From: Dervex Date: Fri, 5 Jul 2024 20:12:47 +0200 Subject: [PATCH] Add `--default` parameter for `config` command --- CHANGELOG.md | 1 + src/cli/config.rs | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d37f5f..64385c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), ### Added - `--async` parameter is now user-exposed for `serve`, `build` and `sourcemap` commands ([#66](https://github.com/argon-rbx/argon/issues/66)) +- `--default` parameter for `config` command that restores all settings to default values ### Fixed diff --git a/src/cli/config.rs b/src/cli/config.rs index aefe44e..540e00a 100644 --- a/src/cli/config.rs +++ b/src/cli/config.rs @@ -2,7 +2,7 @@ use anyhow::Result; use clap::Parser; use colored::Colorize; use open; -use std::fs::File; +use std::fs::{self, File}; use crate::{argon_info, config::Config as GlobalConfig, exit, ext::PathExt, logger, util}; @@ -20,6 +20,10 @@ pub struct Config { /// List all available settings #[arg(short, long)] list: bool, + + /// Restore all settings to default values + #[arg(short, long)] + default: bool, } impl Config { @@ -30,6 +34,22 @@ impl Config { return Ok(()); } + if self.default { + let config_path = util::get_argon_dir()?.join("config.toml"); + + if config_path.exists() { + if GlobalConfig::new().move_to_bin { + trash::delete(config_path)?; + } else { + fs::remove_file(config_path)?; + } + } + + argon_info!("Restored all settings to default values"); + + return Ok(()); + } + match (self.setting, self.value) { (Some(setting), Some(value)) => { let mut config = GlobalConfig::new_mut();