mirror of
https://github.com/martinvonz/jj.git
synced 2024-11-10 14:16:24 +03:00
cli jj config
: add jj config path
command
This commit is contained in:
parent
8a4b3966a6
commit
98948554f7
@ -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
|
||||
|
@ -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.
|
||||
@ -138,6 +140,17 @@ pub(crate) struct ConfigEditArgs {
|
||||
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,
|
||||
@ -149,6 +162,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),
|
||||
}
|
||||
}
|
||||
|
||||
@ -270,3 +284,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,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)
|
||||
@ -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
|
||||
|
||||
|
||||
|
||||
@ -569,6 +571,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
|
||||
|
@ -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;
|
||||
|
||||
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user