Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- License identifiers are now checked for invalid characters and being empty.
- The `PACKIT_DISABLE_PROMPTS` environment variable, which triggers an error when Packit tries to prompt.
- The `LocalMetadataExistence` verifier check.
- The `config reset` command, to reset the Packit configuration file to its default.

### Changes
- The build tests are now turned off by default and can be turned on with `--execute-build-test` (`--skip-build-test` is removed).
Expand Down
4 changes: 4 additions & 0 deletions docs/commands/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ Sets the prebuilds URL of a repository in the config. If no provider is given, t

#### `pit config repositories disable-prebuilds <ID> <VALUE> [--remove-urls]`
Enables or disables prebuild usage for a repository in the config. If the `--remove-urls` flag is given, the URLs are removed if `<VALUE>` is true.

## Reset
#### `pit config reset`
Resets the `Config.toml` to its default configuration. Note that this action cannot be undone.
27 changes: 27 additions & 0 deletions src/cli/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ pub enum ConfigArgs {
/// Manages the repositories in the config
#[clap(subcommand)]
Repositories(RepositoriesArgs),

/// Resets the `Config.toml` to its default configuration
Reset {
/// Skips a confirmation prompt
#[arg(short, long)]
yes: bool,
},
}

/// Manages the repositories in the config.
Expand Down Expand Up @@ -159,6 +166,7 @@ impl HandleCommand for ConfigArgs {
ConfigArgs::Repositories(RepositoriesArgs::DisablePrebuilds { id, value, remove_urls }) => {
self.handle_disable_prebuilds(config, id, *value, *remove_urls)
},
ConfigArgs::Reset { yes } => self.handle_reset(config, *yes),
}
}
}
Expand Down Expand Up @@ -511,4 +519,23 @@ impl ConfigArgs {

true
}

/// Resets the `Config.toml` to its default configuration.
fn handle_reset(&self, config: EditableConfig, yes: bool) {
println!("The following configuration will be removed:");
self.handle_show(config);
println!();

if !yes {
let question = "Resetting the configuration cannot be undone, are you sure you want to continue";
if ask_user(question, QuestionResponse::No).unwrap_or_exit(1).is_no_or_invalid() {
println!("Cancelled configuration reset");
return;
}
}

let new_config = EditableConfig::default();
new_config.save_to(&Config::get_default_path()).unwrap_or_exit_msg("Cannot save new config", 1);
println!("{}", "Successfully reset configuration".to_string().bold().green());
}
}