Skip to content

Commit

Permalink
cli jj config edit: add --print-path argument
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyagr committed Feb 1, 2024
1 parent 7c87fe2 commit 2b97c78
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
14 changes: 12 additions & 2 deletions cli/src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ pub(crate) struct ConfigSetArgs {
pub(crate) struct ConfigEditArgs {
#[clap(flatten)]
pub config_args: ConfigArgs,
/// Print the path to the config file instead of launching an editor
///
/// A config file at that path may or may not exist.
#[arg(long, visible_alias = "path")]
print_path: bool,
}

#[instrument(skip_all)]
Expand Down Expand Up @@ -263,10 +268,15 @@ pub(crate) fn cmd_config_set(

#[instrument(skip_all)]
pub(crate) fn cmd_config_edit(
_ui: &mut Ui,
ui: &mut Ui,
command: &CommandHelper,
args: &ConfigEditArgs,
) -> Result<(), CommandError> {
let config_path = get_new_config_file_path(&args.config_args.get_source_kind(), command)?;
run_ui_editor(command.settings(), &config_path)
if args.print_path {
writeln!(ui.stdout(), "{}", config_path.display())?;
Ok(())
} else {
run_ui_editor(command.settings(), &config_path)
}
}
6 changes: 5 additions & 1 deletion cli/tests/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ Update config file to set the given option to a given value
Start an editor on a jj config file
**Usage:** `jj config edit <--user|--repo>`
**Usage:** `jj config edit [OPTIONS] <--user|--repo>`
###### **Options:**
Expand All @@ -566,6 +566,10 @@ Start an editor on a jj config file
Possible values: `true`, `false`
* `--print-path` — Print the path to the config file instead of launching an editor
Possible values: `true`, `false`
Expand Down
15 changes: 15 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 @@ -544,6 +545,13 @@ fn test_config_edit_user() {
)
.unwrap();
test_env.jj_cmd_ok(&repo_path, &["config", "edit", "--user"]);

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

#[test]
Expand All @@ -562,6 +570,13 @@ fn test_config_edit_repo() {
)
.unwrap();
test_env.jj_cmd_ok(&repo_path, &["config", "edit", "--repo"]);

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

#[test]
Expand Down

0 comments on commit 2b97c78

Please sign in to comment.