diff --git a/src/commands.rs b/src/commands.rs index 6fb9f15..3ff992b 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -12,6 +12,8 @@ pub mod package_path; pub mod tree; pub mod unlink; +use std::path::PathBuf; + use clap::{Parser, Subcommand}; use clap_complete::Shell; use tracing::level_filters::LevelFilter; @@ -131,13 +133,16 @@ pub struct GenerateArgs { generator: Shell, } -//todo: docs, no download #[derive(Parser, Clone, Debug, PartialEq)] pub struct CloneArgs { /// The name of the package you want to clone #[arg()] pub package: String, + /// Path to your dir + #[arg()] + pub path: Option, + /// Download the package without copying it. #[arg(short = 'd')] pub download_only: bool, diff --git a/src/commands/clone.rs b/src/commands/clone.rs index 1bd5843..de3fd2e 100644 --- a/src/commands/clone.rs +++ b/src/commands/clone.rs @@ -1,3 +1,5 @@ +use std::path::PathBuf; + use tracing::{debug, error, info, instrument, warn}; use typst_kit::{download::Downloader, package::PackageStorage}; @@ -18,7 +20,12 @@ use regex::Regex; #[instrument] pub fn run(cmd: &CloneArgs) -> Result { - if has_content(get_current_dir()?)? { + let path: PathBuf = if let Some(path) = &cmd.path { + path.clone() + } else { + get_current_dir()?.into() + }; + if has_content(&path)? { debug!("found content"); if cmd.force { warn!("force used, ignore content"); @@ -29,7 +36,7 @@ pub fn run(cmd: &CloneArgs) -> Result { )); } } - let re = Regex::new(r"@([a-zA-Z]+)\/([a-zA-Z\-]+)\:(\d+)\.(\d+)\.(\d+)").unwrap(); + let re = Regex::new(r"@([a-z]+)\/([a-z\-]+)\:(\d+)\.(\d+)\.(\d+)").unwrap(); let package: &String = &cmd.package; if let Some(cap) = re.captures(package) { let (_, [namespace, package, major, minor, patch]) = cap.extract(); @@ -54,18 +61,19 @@ pub fn run(cmd: &CloneArgs) -> Result { redownload = cmd.redownload, "Skip download..." ); - let string = format!("{}/{package}:{major}.{minor}.{patch}", get_current_dir()?); if cmd.symlink { - symlink_all(val, string)?; + symlink_all(val, path)?; info!("symlinked!"); } else { - copy_dir_all(val, get_current_dir()?)?; + copy_dir_all(val, path)?; info!("copied!"); } return Ok(true); } } + if cmd.redownload {} + let pkg_sto = PackageStorage::new( Some(c_packages()?.into()), Some(d_packages()?.into()), @@ -92,10 +100,10 @@ pub fn run(cmd: &CloneArgs) -> Result { } if cmd.symlink { - symlink_all(val, get_current_dir()?)?; + symlink_all(val, path)?; info!("symlinked!"); } else { - copy_dir_all(val, get_current_dir()?)?; + copy_dir_all(val, path)?; info!("copied!"); }