Files
uv/crates/uv-cache/src/cli.rs
T
Zanie Blue 2586f655bb Rename to uv (#1302)
First, replace all usages in files in-place. I used my editor for this.
If someone wants to add a one-liner that'd be fun.

Then, update directory and file names:

```
# Run twice for nested directories
find . -type d -print0 | xargs -0 rename s/puffin/uv/g
find . -type d -print0 | xargs -0 rename s/puffin/uv/g

# Update files
find . -type f -print0 | xargs -0 rename s/puffin/uv/g
```

Then add all the files again

```
# Add all the files again
git add crates
git add python/uv

# This one needs a force-add
git add -f crates/uv-trampoline
```
2024-02-15 11:19:46 -06:00

44 lines
1.3 KiB
Rust

#![cfg(feature = "clap")]
use std::io;
use std::path::PathBuf;
use clap::Parser;
use directories::ProjectDirs;
use crate::Cache;
#[derive(Parser, Debug, Clone)]
pub struct CacheArgs {
/// Avoid reading from or writing to the cache.
#[arg(global = true, long, short)]
no_cache: bool,
/// Path to the cache directory.
#[arg(global = true, long, env = "PUFFIN_CACHE_DIR")]
cache_dir: Option<PathBuf>,
}
impl TryFrom<CacheArgs> for Cache {
type Error = io::Error;
/// Prefer, in order:
/// 1. A temporary cache directory, if the user requested `--no-cache`.
/// 2. The specific cache directory specified by the user via `--cache-dir` or `PUFFIN_CACHE_DIR`.
/// 3. The system-appropriate cache directory.
/// 4. A `.uv_cache` directory in the current working directory.
///
/// Returns an absolute cache dir.
fn try_from(value: CacheArgs) -> Result<Self, Self::Error> {
if value.no_cache {
Cache::temp()
} else if let Some(cache_dir) = value.cache_dir {
Cache::from_path(cache_dir)
} else if let Some(project_dirs) = ProjectDirs::from("", "", "uv") {
Cache::from_path(project_dirs.cache_dir())
} else {
Cache::from_path(".uv_cache")
}
}
}