ok/jj
1
0
Fork 0
forked from mirrors/jj

Support --user and --repo argument for config list command

This commit is contained in:
Daehyeok Mun 2024-01-13 17:38:55 -08:00 committed by Daehyeok Mun
parent ba4bb928e4
commit 5b6ef63666
3 changed files with 84 additions and 2 deletions

View file

@ -25,6 +25,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* `jj config list` gained a `--include-overridden` option to allow
printing overridden config values.
* `jj config list` now accepts `--user` or `--repo` option to specify
config origin.
### Fixed bugs

View file

@ -71,18 +71,37 @@ pub(crate) enum ConfigSubcommand {
/// List variables set in config file, along with their values.
#[derive(clap::Args, Clone, Debug)]
#[command(group(clap::ArgGroup::new("specific").args(&["repo", "user"])))]
pub(crate) struct ConfigListArgs {
/// An optional name of a specific config option to look up.
#[arg(value_parser = NonEmptyStringValueParser::new())]
pub name: Option<String>,
/// Whether to explicitly include built-in default values in the list.
#[arg(long)]
#[arg(long, conflicts_with = "specific")]
pub include_defaults: bool,
/// Allow printing overridden values.
#[arg(long)]
pub include_overridden: bool,
/// Target the user-level config
#[arg(long)]
user: bool,
/// Target the repo-level config
#[arg(long)]
repo: bool,
// TODO(#1047): Support --show-origin using LayeredConfigs.
// TODO(#1047): Support ConfigArgs (--user or --repo).
}
impl ConfigListArgs {
fn get_source_kind(&self) -> Option<ConfigSource> {
if self.user {
Some(ConfigSource::User)
} else if self.repo {
Some(ConfigSource::Repo)
} else {
//List all variables
None
}
}
}
/// Get the value of a given config option.
@ -158,6 +177,12 @@ pub(crate) fn cmd_config_list(
continue;
}
if let Some(target_source) = args.get_source_kind() {
if target_source != *source {
continue;
}
}
// Skip built-ins if not included.
if !args.include_defaults && *source == ConfigSource::Default {
continue;

View file

@ -126,6 +126,60 @@ fn test_config_list_all() {
"###);
}
#[test]
fn test_config_list_layer() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let user_config_path = test_env.config_path().join("config.toml");
test_env.set_config_path(user_config_path.to_owned());
let repo_path = test_env.env_root().join("repo");
// User
test_env.jj_cmd_ok(
&repo_path,
&["config", "set", "--user", "test-key", "test-val"],
);
test_env.jj_cmd_ok(
&repo_path,
&[
"config",
"set",
"--user",
"test-layered-key",
"test-original-val",
],
);
let stdout = test_env.jj_cmd_success(&repo_path, &["config", "list", "--user"]);
insta::assert_snapshot!(stdout, @r###"
test-key="test-val"
test-layered-key="test-original-val"
"###);
// Repo
test_env.jj_cmd_ok(
&repo_path,
&[
"config",
"set",
"--repo",
"test-layered-key",
"test-layered-val",
],
);
let stdout = test_env.jj_cmd_success(&repo_path, &["config", "list", "--user"]);
insta::assert_snapshot!(stdout, @r###"
test-key="test-val"
"###);
let stdout = test_env.jj_cmd_success(&repo_path, &["config", "list", "--repo"]);
insta::assert_snapshot!(stdout, @r###"
test-layered-key="test-layered-val"
"###);
}
#[test]
fn test_config_layer_override_default() {
let test_env = TestEnvironment::default();