Skip to content

Commit

Permalink
Add --default parameter for config command
Browse files Browse the repository at this point in the history
  • Loading branch information
DervexDev committed Jul 5, 2024
1 parent 35394c3 commit 8fb3588
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 21 additions & 1 deletion src/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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 {
Expand All @@ -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();
Expand Down

0 comments on commit 8fb3588

Please sign in to comment.