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

config cli and docs: make it easier for users to find the config file #2907

Merged
merged 3 commits into from
Feb 3, 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 @@ -35,6 +35,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* `jj config list` now accepts `--user` or `--repo` option to specify
config origin.

* New `jj config path` command to print the config file path without launching
an editor.

* `jj tag list` command prints imported git tags.

* `jj next` and `jj prev` now prompt in the event of the next/previous commit
Expand Down
34 changes: 34 additions & 0 deletions cli/src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ pub(crate) enum ConfigCommand {
Set(ConfigSetArgs),
#[command(visible_alias("e"))]
Edit(ConfigEditArgs),
#[command(visible_alias("p"))]
Path(ConfigPathArgs),
}

/// List variables set in config file, along with their values.
Expand Down Expand Up @@ -132,12 +134,26 @@ pub(crate) struct ConfigSetArgs {
}

/// Start an editor on a jj config file.
///
/// Creates the file if it doesn't already exist regardless of what the editor
/// does.
#[derive(clap::Args, Clone, Debug)]
pub(crate) struct ConfigEditArgs {
ilyagr marked this conversation as resolved.
Show resolved Hide resolved
#[clap(flatten)]
pub config_args: ConfigArgs,
}

/// Print the path to the config file
///
/// A config file at that path may or may not exist.
///
/// See `jj config edit` if you'd like to immediately edit the file.
#[derive(clap::Args, Clone, Debug)]
pub(crate) struct ConfigPathArgs {
#[clap(flatten)]
pub config_args: ConfigArgs,
}

#[instrument(skip_all)]
pub(crate) fn cmd_config(
ui: &mut Ui,
Expand All @@ -149,6 +165,7 @@ pub(crate) fn cmd_config(
ConfigCommand::Get(sub_args) => cmd_config_get(ui, command, sub_args),
ConfigCommand::Set(sub_args) => cmd_config_set(ui, command, sub_args),
ConfigCommand::Edit(sub_args) => cmd_config_edit(ui, command, sub_args),
ConfigCommand::Path(sub_args) => cmd_config_path(ui, command, sub_args),
}
}

Expand Down Expand Up @@ -270,3 +287,20 @@ pub(crate) fn cmd_config_edit(
let config_path = get_new_config_file_path(&args.config_args.get_source_kind(), command)?;
run_ui_editor(command.settings(), &config_path)
}

#[instrument(skip_all)]
pub(crate) fn cmd_config_path(
ui: &mut Ui,
command: &CommandHelper,
args: &ConfigPathArgs,
) -> Result<(), CommandError> {
let config_path = get_new_config_file_path(&args.config_args.get_source_kind(), command)?;
writeln!(
ui.stdout(),
"{}",
config_path
.to_str()
.ok_or_else(|| user_error("The config path is not valid UTF-8"))?
)?;
Ok(())
}
29 changes: 28 additions & 1 deletion cli/tests/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ This document contains the help content for the `jj` command-line program.
* [`jj config get`↴](#jj-config-get)
* [`jj config set`↴](#jj-config-set)
* [`jj config edit`↴](#jj-config-edit)
* [`jj config path`↴](#jj-config-path)
* [`jj describe`↴](#jj-describe)
* [`jj diff`↴](#jj-diff)
* [`jj diffedit`↴](#jj-diffedit)
Expand Down Expand Up @@ -472,6 +473,7 @@ For file locations, supported config options, and other details about jj config,
* `get` — Get the value of a given config option.
* `set` — Update config file to set the given option to a given value
* `edit` — Start an editor on a jj config file
* `path` — Print the path to the config file



Expand Down Expand Up @@ -552,7 +554,9 @@ Update config file to set the given option to a given value

## `jj config edit`

Start an editor on a jj config file
Start an editor on a jj config file.

Creates the file if it doesn't already exist regardless of what the editor does.

**Usage:** `jj config edit <--user|--repo>`

Expand All @@ -569,6 +573,29 @@ Start an editor on a jj config file



## `jj config path`

Print the path to the config file

A config file at that path may or may not exist.

See `jj config edit` if you'd like to immediately edit the file.

**Usage:** `jj config path <--user|--repo>`

###### **Options:**

* `--user` — Target the user-level config

Possible values: `true`, `false`

* `--repo` — Target the repo-level config

Possible values: `true`, `false`




## `jj describe`

Update the change description or other metadata
Expand Down
21 changes: 21 additions & 0 deletions cli/tests/test_config_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use insta::assert_snapshot;
use itertools::Itertools;
use regex::Regex;

Expand Down Expand Up @@ -564,6 +565,26 @@ fn test_config_edit_repo() {
test_env.jj_cmd_ok(&repo_path, &["config", "edit", "--repo"]);
}

#[test]
fn test_config_path() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");

assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["config", "path", "--user"]),
@r###"
$TEST_ENV/config
"###
);
assert_snapshot!(
test_env.jj_cmd_success(&repo_path, &["config", "path", "--repo"]),
@r###"
$TEST_ENV/repo/.jj/repo/config.toml
"###
);
}

#[test]
fn test_config_edit_repo_outside_repo() {
let test_env = TestEnvironment::default();
Expand Down
40 changes: 33 additions & 7 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,29 @@ These are the config settings available to jj/Jujutsu.

## Config files and TOML

The config settings are loaded from the following locations. Less common ways to
specify `jj` config settings are discussed in a later section.
`jj` loads several types of config settings:

* [The user config file]
* `.jj/repo/config.toml` (per-repository)
- The built-in settings. These cannot be edited. They can be viewed in the
`cli/src/config/` directory in `jj`'s source repo.
ilyagr marked this conversation as resolved.
Show resolved Hide resolved

See the [TOML site] and the [syntax guide] for a description of the syntax.
- The user settings. These can be edited with `jj config edit --user`. User
settings are located in [the user config file], which can be found with `jj
config path --user`.

[The user config file]: #user-config-file
- The repo settings. These can be edited with `jj config edit --repo` and are
located in `.jj/repo/config.toml`.

- Settings [specified in the command-line](#specifying-config-on-the-command-line).

These are listed in the order they are loaded; the settings from earlier items
in
the list are overridden by the settings from later items if they disagree. Every
type of config except for the built-in settings is optional.

See the [TOML site] and the [syntax guide] for a detailed description of the
syntax. We cover some of the basics below.

[the user config file]: #user-config-file
[TOML site]: https://toml.io/en/
[syntax guide]: https://toml.io/en/v1.0.0

Expand Down Expand Up @@ -561,7 +575,17 @@ executable on your system](https://facebook.github.io/watchman/docs/install).

Debugging commands are available under `jj debug watchman`.

# User config file
## Ways to specify `jj` config: details

### User config file

An easy way to find the user config file is:

```bash
jj config path --user
```

The rest of this section covers the details of where this file can be located.

On all platforms, the user's global `jj` configuration file is located at either
`~/.jjconfig.toml` (where `~` represents `$HOME` on Unix-likes, or
Expand All @@ -584,6 +608,8 @@ default locations. For example,
env JJ_CONFIG=/dev/null jj log # Ignores any settings specified in the config file.
```

### Specifying config on the command-line

You can use one or more `--config-toml` options on the command line to specify
additional configuration settings. This overrides settings defined in config
files or environment variables. For example,
Expand Down