Skip to content

Commit

Permalink
add(clone): path and normalized behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Thumuss committed Aug 20, 2024
1 parent b634395 commit d231ef3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
7 changes: 6 additions & 1 deletion src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<PathBuf>,

/// Download the package without copying it.
#[arg(short = 'd')]
pub download_only: bool,
Expand Down
22 changes: 15 additions & 7 deletions src/commands/clone.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::path::PathBuf;

use tracing::{debug, error, info, instrument, warn};
use typst_kit::{download::Downloader, package::PackageStorage};

Expand All @@ -18,7 +20,12 @@ use regex::Regex;

#[instrument]
pub fn run(cmd: &CloneArgs) -> Result<bool> {
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");
Expand All @@ -29,7 +36,7 @@ pub fn run(cmd: &CloneArgs) -> Result<bool> {
));
}
}
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();
Expand All @@ -54,18 +61,19 @@ pub fn run(cmd: &CloneArgs) -> Result<bool> {
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()),
Expand All @@ -92,10 +100,10 @@ pub fn run(cmd: &CloneArgs) -> Result<bool> {
}

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!");
}

Expand Down

0 comments on commit d231ef3

Please sign in to comment.