Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: deprecate --config-toml #5119

Merged
merged 2 commits into from
Dec 17, 2024
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Deprecations

* `--config-toml=TOML` is deprecated in favor of `--config=NAME=VALUE` and
`--config-file=PATH`.

* The `Signature.username()` template method is deprecated for
`Signature().email().local()`.

Expand Down
17 changes: 12 additions & 5 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 @@ -3109,8 +3109,9 @@ pub struct EarlyArgs {
/// constructs (such as array notation), quotes can be omitted.
#[arg(long, value_name = "NAME=VALUE", global = true)]
pub config: Vec<String>,
/// Additional configuration options (can be repeated)
#[arg(long, value_name = "TOML", global = true)]
/// Additional configuration options (can be repeated) (DEPRECATED)
// TODO: delete --config-toml in jj 0.31+
#[arg(long, value_name = "TOML", global = true, hide = true)]
pub config_toml: Vec<String>,
/// Additional configuration files (can be repeated)
#[arg(long, value_name = "PATH", global = true, value_hint = clap::ValueHint::FilePath)]
Expand Down Expand Up @@ -3334,6 +3335,12 @@ fn handle_early_args(
let args = EarlyArgs::from_arg_matches(&early_matches).unwrap();

let old_layers_len = config.layers().len();
if !args.config_toml.is_empty() {
writeln!(
ui.warning_default(),
"--config-toml is deprecated; use --config or --config-file instead."
)?;
}
config.extend_layers(parse_config_args(&args.merged_config_args(&early_matches))?);

// Command arguments overrides any other configuration including the
Expand Down Expand Up @@ -3682,11 +3689,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
1 change: 0 additions & 1 deletion cli/tests/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ To get started, see the tutorial at https://martinvonz.github.io/jj/latest/tutor
* `--config <NAME=VALUE>` — Additional configuration options (can be repeated)
The name should be specified as TOML dotted keys. The value should be specified as a TOML expression. If string value doesn't contain any TOML constructs (such as array notation), quotes can be omitted.
* `--config-toml <TOML>` — Additional configuration options (can be repeated)
* `--config-file <PATH>` — Additional configuration files (can be repeated)
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
6 changes: 2 additions & 4 deletions cli/tests/test_completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ fn test_bookmark_names() {
--quiet Silence non-primary command output
--no-pager Disable the pager
--config Additional configuration options (can be repeated)
--config-toml Additional configuration options (can be repeated)
--config-file Additional configuration files (can be repeated)
--help Print help (see more with '--help')
");
Expand Down Expand Up @@ -337,14 +336,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
Loading