1use crate::error::Result;
3use crate::types::xvcroot::XvcRoot;
4use clap::Parser;
5
6use relative_path::RelativePath;
7use xvc_logging::{output, XvcOutputSender};
8
9#[derive(Debug, Parser, Clone)]
10#[command(name = "root")]
11pub struct RootCLI {
13 #[arg(long)]
14 absolute: bool,
16}
17
18pub fn run(output_snd: &XvcOutputSender, xvc_root: &XvcRoot, opts: RootCLI) -> Result<()> {
33 if opts.absolute {
34 output!("{}", xvc_root.absolute_path().to_string_lossy());
35 } else {
36 let current_dir = xvc_root.config().current_dir.option.to_path_buf();
37
38 let rel_dir = RelativePath::new(¤t_dir.to_string_lossy()).relative(
39 RelativePath::new(&xvc_root.absolute_path().to_string_lossy()),
40 );
41 if rel_dir == "" {
42 output!(output_snd, ".");
43 } else {
44 output!(output_snd, "{}", rel_dir);
45 }
46 }
47 Ok(())
48}