Skip to main content

resolve_output_path

Function resolve_output_path 

Source
pub fn resolve_output_path(
    output_arg: Option<String>,
    url: &str,
    default_name: &str,
) -> String
Expand description

Resolve the final output path for a download.

Handles three cases:

  1. output_arg is None: Extract filename from URL
  2. output_arg is a directory: Append filename from URL to directory
  3. output_arg is a file path: Use it directly

§Arguments

  • output_arg - User-provided output path (can be file or directory)
  • url - Source URL for filename extraction
  • default_name - Fallback filename if URL doesn’t contain one

§Returns

The resolved output file path.

§Example

use kget::resolve_output_path;

// No output specified - use filename from URL
let path = resolve_output_path(None, "https://example.com/file.zip", "download");
assert_eq!(path, "file.zip");

// Custom filename
let path = resolve_output_path(Some("myfile.zip".to_string()), "https://example.com/file.zip", "download");
assert_eq!(path, "myfile.zip");