Debian Codegraph @

cli/src/commands/config/path.rs

raw
1 // Copyright 2020 The Jujutsu Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 use std::io::Write as _;
16
17 use jj_lib::file_util;
18 use tracing::instrument;
19
20 use super::ConfigLevelArgs;
21 use crate::cli_util::CommandHelper;
22 use crate::command_error::CommandError;
23 use crate::command_error::user_error;
24 use crate::ui::Ui;
25
26 /// Print the paths to the config files
27 ///
28 /// A config file at that path may or may not exist.
29 ///
30 /// If `--repo` or `--workspace` is specified and the config file does not
31 /// exist, jj will generate a new config directory for this repo/workspace and
32 /// print the path to the config file in that directory.
33 ///
34 /// See `jj config edit` if you'd like to immediately edit a file.
35 #[derive(clap::Args, Clone, Debug)]
36 pub struct ConfigPathArgs {
37 #[command(flatten)]
38 pub level: ConfigLevelArgs,
39 }
40
41 #[instrument(skip_all)]
42 pub async fn cmd_config_path(
43 ui: &mut Ui,
44 command: &CommandHelper,
45 args: &ConfigPathArgs,
46 ) -> Result<(), CommandError> {
47 for config_path in args.level.config_paths(ui, command.config_env())? {
48 let path_bytes = file_util::path_to_bytes(&config_path).map_err(user_error)?;
49 ui.stdout().write_all(path_bytes)?;
50 writeln!(ui.stdout())?;
51 }
52 Ok(())
53 }