-
Notifications
You must be signed in to change notification settings - Fork 343
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 a key, which is part of a table, might leave that table empty. For now we do not delete such empty tables, as there may be cases where an empty table is semantically meaningful (#4458 (comment)). For example: ```toml [table] key = "value" [another-table] key = "value" ``` Running `jj config unset --user table.key` will leave us with `table` being empty: ```toml [table] [another-table] key = "value" ```
- Loading branch information
Showing
6 changed files
with
193 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
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,50 @@ | ||
// Copyright 2024 The Jujutsu Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
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; | ||
use crate::ui::Ui; | ||
|
||
/// 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( | ||
_ui: &mut Ui, | ||
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() | ||
))); | ||
} | ||
|
||
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
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