use crate::error::Result;
use crate::types::xvcroot::XvcRoot;
use clap::Parser;
use relative_path::RelativePath;
use xvc_logging::{output, XvcOutputSender};
#[derive(Debug, Parser, Clone)]
#[command(name = "root")]
pub struct RootCLI {
#[arg(long)]
absolute: bool,
}
pub fn run(output_snd: &XvcOutputSender, xvc_root: &XvcRoot, opts: RootCLI) -> Result<()> {
if opts.absolute {
output!("{}", xvc_root.absolute_path().to_string_lossy());
} else {
let current_dir = xvc_root.current_dir().to_path_buf();
let rel_dir = RelativePath::new(¤t_dir.to_string_lossy()).relative(
RelativePath::new(&xvc_root.absolute_path().to_string_lossy()),
);
if rel_dir == "" {
output!(output_snd, ".");
} else {
output!(output_snd, "{}", rel_dir);
}
}
Ok(())
}