-
Notifications
You must be signed in to change notification settings - Fork 379
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow unsetting config values similar to `git config unset`. ```bash $ jj config set --user some-key some-val $ jj config get some-key some-val $ jj config unset --user some-key $ jj config get some-key Config error: configuration property "some-key" not found For help, see https://martinvonz.github.io/jj/latest/config/. ``` Unsetting nonexistent keys will result in an error: ```bash $ jj config unset --user nonexistent Error: configuration property "nonexistent" not found For help, see https://martinvonz.github.io/jj/latest/config/. ``` If unsetting a key leaves the hosting table empty, the table is removed as well. Given the following config: ```toml [table] key = value [another-table] key = value ``` Running `jj config unset --user table.key` will leave us with: ```toml [another-table] key = value ```
- Loading branch information
Showing
4 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use tracing::instrument; | ||
|
||
use super::ConfigLevelArgs; | ||
use crate::cli_util::get_new_config_file_path; | ||
use crate::cli_util::CommandHelper; | ||
use crate::command_error::user_error; | ||
use crate::command_error::CommandError; | ||
use crate::config::remove_config_value_from_file; | ||
use crate::config::ConfigNamePathBuf; | ||
|
||
/// Update config file to unset the given option. | ||
#[derive(clap::Args, Clone, Debug)] | ||
pub struct ConfigUnsetArgs { | ||
#[arg(required = true)] | ||
name: ConfigNamePathBuf, | ||
#[command(flatten)] | ||
level: ConfigLevelArgs, | ||
} | ||
|
||
#[instrument(skip_all)] | ||
pub fn cmd_config_unset( | ||
command: &CommandHelper, | ||
args: &ConfigUnsetArgs, | ||
) -> Result<(), CommandError> { | ||
let config_path = get_new_config_file_path(&args.level.expect_source_kind(), command)?; | ||
if config_path.is_dir() { | ||
return Err(user_error(format!( | ||
"Can't set config in path {path} (dirs not supported)", | ||
path = config_path.display() | ||
))); | ||
} | ||
|
||
// TODO(pylbrecht): do we need to check_wc_author() here? | ||
|
||
remove_config_value_from_file(&args.name, &config_path) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters