Skip to content

Commit

Permalink
cli: replace --config-toml=TOML with --config=NAME=VALUE
Browse files Browse the repository at this point in the history
  • Loading branch information
yuja committed Dec 17, 2024
1 parent 60078e9 commit cfb27c7
Show file tree
Hide file tree
Showing 26 changed files with 119 additions and 192 deletions.
6 changes: 3 additions & 3 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2609,7 +2609,7 @@ pub fn print_snapshot_stats(
- Adding the file to `.gitignore`
- Run `jj config set --repo snapshot.max-new-file-size {size}`
This will increase the maximum file size allowed for new files, in this repository only.
- Run `jj --config-toml 'snapshot.max-new-file-size={size}' st`
- Run `jj --config snapshot.max-new-file-size={size} st`
This will increase the maximum file size allowed for new files, for this command only.
"
)?;
Expand Down Expand Up @@ -3682,11 +3682,11 @@ impl CliRunner {
maybe_cwd_workspace_loader
};

// Apply workspace configs and --config-toml arguments.
// Apply workspace configs and --config arguments.
ui.reset(&config)?;

// If -R is specified, check if the expanded arguments differ. Aliases
// can also be injected by --config-toml, but that's obviously wrong.
// can also be injected by --config, but that's obviously wrong.
if args.global_args.repository.is_some() {
let new_string_args = expand_args(ui, &self.app, env::args_os(), &config).ok();
if new_string_args.as_ref() != Some(&string_args) {
Expand Down
32 changes: 13 additions & 19 deletions cli/src/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ use crate::config::ConfigEnv;
use crate::config::CONFIG_SCHEMA;
use crate::ui::Ui;

const BOOKMARK_HELP_TEMPLATE: &str = r#"
[template-aliases]
"bookmark_help()" = """
const BOOKMARK_HELP_TEMPLATE: &str = r#"template-aliases.'bookmark_help()'='''
" " ++
if(normal_target,
if(normal_target.description(),
Expand All @@ -46,8 +44,7 @@ if(normal_target,
),
"(conflicted bookmark)",
)
"""
"#;
'''"#;

/// A helper function for various completer functions. It returns
/// (candidate, help) assuming they are separated by a space.
Expand All @@ -64,7 +61,7 @@ pub fn local_bookmarks() -> Vec<CompletionCandidate> {
.build()
.arg("bookmark")
.arg("list")
.arg("--config-toml")
.arg("--config")
.arg(BOOKMARK_HELP_TEMPLATE)
.arg("--template")
.arg(r#"if(!remote, name ++ bookmark_help()) ++ "\n""#)
Expand All @@ -86,7 +83,7 @@ pub fn tracked_bookmarks() -> Vec<CompletionCandidate> {
.arg("bookmark")
.arg("list")
.arg("--tracked")
.arg("--config-toml")
.arg("--config")
.arg(BOOKMARK_HELP_TEMPLATE)
.arg("--template")
.arg(r#"if(remote, name ++ '@' ++ remote ++ bookmark_help() ++ "\n")"#)
Expand All @@ -108,7 +105,7 @@ pub fn untracked_bookmarks() -> Vec<CompletionCandidate> {
.arg("bookmark")
.arg("list")
.arg("--all-remotes")
.arg("--config-toml")
.arg("--config")
.arg(BOOKMARK_HELP_TEMPLATE)
.arg("--template")
.arg(
Expand Down Expand Up @@ -146,7 +143,7 @@ pub fn bookmarks() -> Vec<CompletionCandidate> {
.arg("bookmark")
.arg("list")
.arg("--all-remotes")
.arg("--config-toml")
.arg("--config")
.arg(BOOKMARK_HELP_TEMPLATE)
.arg("--template")
.arg(
Expand Down Expand Up @@ -238,7 +235,7 @@ fn revisions(revisions: Option<&str>) -> Vec<CompletionCandidate> {
cmd.arg("bookmark")
.arg("list")
.arg("--all-remotes")
.arg("--config-toml")
.arg("--config")
.arg(BOOKMARK_HELP_TEMPLATE)
.arg("--template")
.arg(
Expand Down Expand Up @@ -278,7 +275,7 @@ fn revisions(revisions: Option<&str>) -> Vec<CompletionCandidate> {
.build()
.arg("tag")
.arg("list")
.arg("--config-toml")
.arg("--config")
.arg(BOOKMARK_HELP_TEMPLATE)
.arg("--template")
.arg(r#"name ++ bookmark_help() ++ "\n""#)
Expand Down Expand Up @@ -370,8 +367,8 @@ pub fn workspaces() -> Vec<CompletionCandidate> {
with_jj(|jj, _| {
let output = jj
.build()
.arg("--config-toml")
.arg(r#"templates.commit_summary = 'if(description, description.first_line(), "(no description set)")'"#)
.arg("--config")
.arg(r#"templates.commit_summary='if(description, description.first_line(), "(no description set)")'"#)
.arg("workspace")
.arg("list")
.output()
Expand Down Expand Up @@ -472,8 +469,7 @@ fn all_files_from_rev(rev: String, current: &std::ffi::OsStr) -> Vec<CompletionC
.arg("list")
.arg("--revision")
.arg(rev)
.arg("--config-toml")
.arg("ui.allow-filesets = true")
.arg("--config=ui.allow-filesets=true")
.arg(current_prefix_to_fileset(current))
.stdout(std::process::Stdio::piped())
.spawn()
Expand Down Expand Up @@ -505,8 +501,7 @@ fn modified_files_from_rev_with_jj_cmd(
};
cmd.arg("diff")
.arg("--summary")
.arg("--config-toml")
.arg("ui.allow-filesets = true")
.arg("--config=ui.allow-filesets=true")
.arg(current_prefix_to_fileset(current));
match rev {
(rev, None) => cmd.arg("--revision").arg(rev),
Expand Down Expand Up @@ -558,8 +553,7 @@ fn conflicted_files_from_rev(rev: &str, current: &std::ffi::OsStr) -> Vec<Comple
.arg("--list")
.arg("--revision")
.arg(rev)
.arg("--config-toml")
.arg("ui.allow-filesets = true")
.arg("--config=ui.allow-filesets=true")
.arg(current_prefix_to_fileset(current))
.output()
.map_err(user_error)?;
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/test_builtin_aliases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn set_up(trunk_name: &str) -> (TestEnvironment, PathBuf) {
&[
"git",
"clone",
"--config-toml=git.auto-local-bookmark=true",
"--config=git.auto-local-bookmark=true",
origin_git_repo_path.to_str().unwrap(),
"local",
],
Expand Down
7 changes: 3 additions & 4 deletions cli/tests/test_commit_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fn test_commit_interactive() {
&workspace_path,
&[
"commit",
"--config-toml=ui.diff-editor='false'",
"--config=ui.diff-editor='false'",
"--tool=fake-diff-editor",
],
);
Expand Down Expand Up @@ -357,9 +357,8 @@ fn test_commit_reset_author() {
&repo_path,
&[
"commit",
"--config-toml",
r#"user.name = "Ove Ridder"
user.email = "[email protected]""#,
"--config=user.name=Ove Ridder",
"[email protected]",
"--reset-author",
"-m1",
],
Expand Down
30 changes: 7 additions & 23 deletions cli/tests/test_commit_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ fn test_mine_is_true_when_author_is_user() {
test_env.jj_cmd_ok(
&repo_path,
&[
"--config-toml=user.email='[email protected]'",
"--config-toml=user.name='John Doe'",
"[email protected]",
"--config=user.name=John Doe",
"new",
],
);
Expand Down Expand Up @@ -280,11 +280,7 @@ fn test_log_builtin_templates() {

test_env.jj_cmd_ok(
&repo_path,
&[
"--config-toml=user.email=''",
"--config-toml=user.name=''",
"new",
],
&["--config=user.email=''", "--config=user.name=''", "new"],
);
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "my-bookmark"]);

Expand Down Expand Up @@ -353,11 +349,7 @@ fn test_log_builtin_templates_colored() {

test_env.jj_cmd_ok(
&repo_path,
&[
"--config-toml=user.email=''",
"--config-toml=user.name=''",
"new",
],
&["--config=user.email=''", "--config=user.name=''", "new"],
);
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "my-bookmark"]);

Expand Down Expand Up @@ -421,11 +413,7 @@ fn test_log_builtin_templates_colored_debug() {

test_env.jj_cmd_ok(
&repo_path,
&[
"--config-toml=user.email=''",
"--config-toml=user.name=''",
"new",
],
&["--config=user.email=''", "--config=user.name=''", "new"],
);
test_env.jj_cmd_ok(&repo_path, &["bookmark", "create", "my-bookmark"]);

Expand Down Expand Up @@ -751,7 +739,7 @@ fn test_log_customize_short_id() {
&repo_path,
&[
"log",
"--config-toml",
"--config",
&format!(r#"{decl}='id.shortest(5).prefix().upper() ++ "_" ++ id.shortest(5).rest()'"#),
],
);
Expand All @@ -766,11 +754,7 @@ fn test_log_customize_short_id() {
&repo_path,
&[
"log",
"--config-toml",
r#"
[template-aliases]
'format_short_change_id(id)'='format_short_id(id).upper()'
"#,
"--config=template-aliases.'format_short_change_id(id)'='format_short_id(id).upper()'",
],
);
insta::assert_snapshot!(stdout, @r###"
Expand Down
5 changes: 2 additions & 3 deletions cli/tests/test_completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,13 @@ fn test_aliases_are_completed() {
);
insta::assert_snapshot!(stdout, @"repo-alias");

// cannot load aliases from --config-toml flag
// cannot load aliases from --config flag
let stdout = test_env.jj_cmd_success(
test_env.env_root(),
&[
"--",
"jj",
"--config-toml",
"aliases.cli-alias = ['bookmark']",
"--config=aliases.cli-alias=['bookmark']",
"cli-al",
],
);
Expand Down
10 changes: 5 additions & 5 deletions cli/tests/test_config_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ bar
"list",
"multiline",
"--include-overridden",
"--config-toml=multiline='single'",
"--config=multiline='single'",
],
);
insta::assert_snapshot!(stdout, @r"
Expand Down Expand Up @@ -293,7 +293,7 @@ fn test_config_layer_override_default() {
"config",
"list",
config_key,
"--config-toml",
"--config",
&format!("{config_key}={value:?}", value = "command-arg"),
],
);
Expand All @@ -309,7 +309,7 @@ fn test_config_layer_override_default() {
"list",
config_key,
"--include-overridden",
"--config-toml",
"--config",
&format!("{config_key}={value:?}", value = "command-arg"),
],
);
Expand Down Expand Up @@ -381,7 +381,7 @@ fn test_config_layer_override_env() {
"config",
"list",
config_key,
"--config-toml",
"--config",
&format!("{config_key}={value:?}", value = "command-arg"),
],
);
Expand All @@ -397,7 +397,7 @@ fn test_config_layer_override_env() {
"list",
config_key,
"--include-overridden",
"--config-toml",
"--config",
&format!("{config_key}={value:?}", value = "command-arg"),
],
);
Expand Down
10 changes: 4 additions & 6 deletions cli/tests/test_describe_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,9 +602,8 @@ fn test_describe_author() {
&repo_path,
&[
"describe",
"--config-toml",
r#"user.name = "Ove Ridder"
user.email = "[email protected]""#,
"--config=user.name=Ove Ridder",
"[email protected]",
"--no-edit",
"--reset-author",
],
Expand All @@ -628,9 +627,8 @@ fn test_describe_author() {
"describe",
"@---",
"@-",
"--config-toml",
r#"user.name = "Ove Ridder"
user.email = "[email protected]""#,
"--config=user.name=Ove Ridder",
"[email protected]",
"--reset-author",
],
);
Expand Down
Loading

0 comments on commit cfb27c7

Please sign in to comment.