diff --git a/README.md b/README.md index e9400b0..5d3feb4 100644 --- a/README.md +++ b/README.md @@ -49,12 +49,17 @@ ghr [OPTIONS] --repo | Clone | `-c` | `--clone ` | Clone repository with optional branch/tag/commit | | Download | `-d` | `--download ` | Download specific version (or "latest") | | Filter | `-f` | `--filter ` | Filter assets by comma-separated patterns | -| Output Dir | `-o` | `--output-dir ` | Save downloads to specified directory | | Info | `-i` | `--info ` | Show info about specific versions (comma-separated) | | Number | `-n` | `--num ` | Number of releases to list (default: 1) | | Concurrency | `-j` | `--concurrency ` | Maximum number of concurrent downloads (default: 5) | | Verbose | `-v` | `--verbose` | Increase verbosity (-v, -vv for more detail) | +### Positional Arguments + +| Argument | Description | +|----------|-------------| +| `[DIRECTORY]` | Directory for downloads or clone destination | + ## Examples ### List Latest Release @@ -72,17 +77,21 @@ ghr -r owner/repo -n 5 ### Download Latest Release ```bash -# Download all assets from latest release +# Download all assets from latest release to current directory ghr -r owner/repo -d latest # Download to specific directory -ghr -r owner/repo -d latest -o ./downloads +ghr -r owner/repo -d latest ./downloads ``` ### Download Specific Version ```bash +# Download to current directory ghr -r owner/repo -d v1.2.3 + +# Download to specific directory +ghr -r owner/repo -d v1.2.3 ./releases ``` ### Download with Filtering @@ -197,7 +206,7 @@ ghr -r owner/private-repo -d latest ```yaml - name: Download release asset run: | - ghr -r owner/repo -d latest -f "linux,amd64" -o ./bin + ghr -r owner/repo -d latest -f "linux,amd64" ./bin ``` #### GitLab CI @@ -205,13 +214,13 @@ ghr -r owner/private-repo -d latest ```yaml download_release: script: - - ghr -r owner/repo -d v1.0.0 -t $GITHUB_TOKEN -o ./artifacts + - ghr -r owner/repo -d v1.0.0 -t $GITHUB_TOKEN ./artifacts ``` #### Jenkins ```groovy -sh 'ghr -r owner/repo -d latest -T /var/jenkins/.github_token' +sh 'ghr -r owner/repo -d latest -T /var/jenkins/.github_token ./bin' ``` ## Authentication @@ -290,7 +299,7 @@ ghr -r owner/repo -d latest -vv ```bash #!/bin/bash -ghr -r mycompany/app -d latest -f "linux,amd64" -o /tmp +ghr -r mycompany/app -d latest -f "linux,amd64" /tmp sudo dpkg -i /tmp/app_*_amd64.deb ``` @@ -299,7 +308,7 @@ sudo dpkg -i /tmp/app_*_amd64.deb ```bash #!/bin/bash for platform in linux darwin windows; do - ghr -r owner/repo -d v1.0.0 -f "$platform" -o "./dist/$platform" + ghr -r owner/repo -d v1.0.0 -f "$platform" "./dist/$platform" done ``` @@ -312,7 +321,7 @@ latest=$(ghr -r owner/repo -n 1 2>&1 | grep "Tag:" | awk '{print $2}') if [ "$latest" != "$current_version" ]; then echo "New version available: $latest" - ghr -r owner/repo -d latest -o ./updates + ghr -r owner/repo -d latest ./updates fi ``` diff --git a/src/cli.rs b/src/cli.rs index acd0cf5..6cca904 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,5 +1,4 @@ use clap::{ArgAction, Parser}; -use std::path::PathBuf; /// CLI arguments #[derive(Parser)] @@ -37,10 +36,6 @@ pub struct Cli { #[arg(short = 's', long = "search")] pub search: Option, - /// Directory to save downloaded assets (defaults to current directory) - #[arg(short = 'o', long = "output-dir")] - pub output_dir: Option, - /// Show information about a specific version, multiple versions can be separated by commas. #[arg(short = 'i', long = "info")] pub info: Option, @@ -61,8 +56,10 @@ pub struct Cli { #[arg(short = 'c', long = "clone", value_name = "URL[:REF]")] pub clone: Option, - /// Local directory for cloned repository (defaults to repository name) - #[arg(value_name = "DIRECTORY", requires = "clone")] + /// Directory for operation (clone destination or download location) + /// - For clone: defaults to repository name + /// - For download: defaults to current directory + #[arg(value_name = "DIRECTORY")] pub directory: Option, #[arg(short = 'v', long = "verbose", action = ArgAction::Count)] diff --git a/src/main.rs b/src/main.rs index 60c3ccf..0390814 100644 --- a/src/main.rs +++ b/src/main.rs @@ -158,15 +158,10 @@ async fn main() -> Result<()> { }; // Create output directory if specified - if let Some(output_dir) = &cli.output_dir { - fs::create_dir_all(output_dir).map_err(|e| { - format!( - "Failed to create output directory '{}': {}", - output_dir.display(), - e - ) - })?; - jinfo!("Saving assets to: {}", output_dir.display()); + if let Some(directory) = &cli.directory { + fs::create_dir_all(directory) + .map_err(|e| format!("Failed to create output directory '{}': {}", directory, e))?; + jinfo!("Saving assets to: {}", directory); } // Collect assets to download with filtering @@ -197,8 +192,8 @@ async fn main() -> Result<()> { let size = asset.size; // Construct output path - let output_path = if let Some(output_dir) = &cli.output_dir { - output_dir.join(name) + let output_path = if let Some(directory) = &cli.directory { + PathBuf::from(directory).join(name) } else { PathBuf::from(name) };