Skip to content

Commit

Permalink
path argument for download and upload commands
Browse files Browse the repository at this point in the history
  • Loading branch information
harshdoesdev committed Sep 29, 2023
1 parent a90da15 commit c8cd096
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
11 changes: 8 additions & 3 deletions src/commands/download.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub async fn download(
remote_client: vercel_cache_helper::vercel::remote_cache_client::RemoteClient,
path: &Option<std::path::PathBuf>,
) -> vercel_cache_helper::Result<()> {
let cache_dir = if let Some(cache_dir) = vercel_cache_helper::utils::get_cache_dir() {
println!("Cache dir found: {:?}", cache_dir);
Expand All @@ -8,9 +9,13 @@ pub async fn download(
return Ok(());
};

let current_dir = std::env::current_dir()?;
let cache_key_path = current_dir.join(".cache").join(".cache_key");
let build_dir = current_dir.join(".build");
let project_dir = if let Some(path) = path {
path.clone()
} else {
std::env::current_dir()?
};
let cache_key_path: std::path::PathBuf = project_dir.join(".cache").join(".cache_key");
let build_dir = project_dir.join(".build");

if !build_dir.exists() {
std::fs::create_dir(&build_dir).expect("Failed to create .build dir.");
Expand Down
12 changes: 9 additions & 3 deletions src/commands/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::io::{Read, Seek};

pub async fn upload(
remote_client: vercel_cache_helper::vercel::remote_cache_client::RemoteClient,
path: &Option<std::path::PathBuf>,
) -> vercel_cache_helper::Result<()> {
let cache_dir = if let Some(cache_dir) = vercel_cache_helper::utils::get_cache_dir() {
println!("Cache dir found: {:?}", cache_dir);
Expand All @@ -11,9 +12,14 @@ pub async fn upload(
return Ok(());
};

let current_dir = std::env::current_dir()?;
let cache_key_path = current_dir.join(".cache").join(".cache_key");
let build_dir = current_dir.join(".build");
let project_dir = if let Some(path) = path {
path.clone()
} else {
std::env::current_dir()?
};

let cache_key_path = project_dir.join(".cache").join(".cache_key");
let build_dir = project_dir.join(".build");

if let Some(dot_cache_folder) = &cache_key_path.parent() {
if !dot_cache_folder.exists() {
Expand Down
17 changes: 12 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ struct Cli {

#[derive(Subcommand)]
enum Commands {
Download {},
Upload {},
Download {
#[arg(short, long)]
path: Option<std::path::PathBuf>
},
Upload {
#[arg(short, long)]
path: Option<std::path::PathBuf>
},
}

#[tokio::main]
Expand All @@ -30,11 +36,12 @@ async fn main() -> vercel_cache_helper::Result<()> {
let result_future: std::pin::Pin<
Box<dyn std::future::Future<Output = Result<(), vercel_cache_helper::Error>>>,
> = match &cli.command {
Some(Commands::Download {}) => Box::pin(vercel_cache_helper::commands::download::download(
Some(Commands::Download { path }) => Box::pin(vercel_cache_helper::commands::download::download(
remote_client,
path,
)),
Some(Commands::Upload {}) => {
Box::pin(vercel_cache_helper::commands::upload::upload(remote_client))
Some(Commands::Upload { path }) => {
Box::pin(vercel_cache_helper::commands::upload::upload(remote_client, path,))
}
None => Box::pin(async { Ok(()) }),
};
Expand Down

0 comments on commit c8cd096

Please sign in to comment.